Solved

URGENT - Need help with timer event handler

Posted on 2006-10-29
3
253 Views
Last Modified: 2010-04-16
This is urgent, hence the 500 pts.

I've created a subclass of the Timer class.  My main program creates an ArrayList of this new Timer class, clsTimer.  I would like to be able to hook up a new Tick event handler for each timer as I see fit.  For instance, in the main form, I have written a routine called LoadData() that I would like to use as the Tick event of the first clsTimer instance.  The next instance of clsTimer can hook to a totally different routine.  I've done the following:


// clsTimer
using System;
using System.Windows.Forms;

namespace Inhallation
{
      /// <summary>
      /// Summary description for clstimer.
      /// </summary>
      public class clsTimer : System.Windows.Forms.Timer

      {
            public int TimerNum;
            public string TimerName;
            public Timer objTimer;
            //public int Interval;
            public bool StartTimer;


            public clsTimer(string timername, int interval, bool starttimer)
            {
                  //
                  // TODO: Add constructor logic here
                  //
                  this.TimerName  = timername;
                  //this.Interval = interval;
                  objTimer.Interval = interval;

                  if (this.StartTimer)
                        objTimer.Start();
                  
            }

            public clsTimer(bool starttimer)
            {
                  if (starttimer)
                        this.objTimer.Start();
                  else
                        this.objTimer.Stop();
            }

            
      }
}

From my main form, I do this:

private void Start_Environmental_Monitoring(string name, int interval)
{
                  // Initializes equipment and starts the 2701

                  // For test purposes, use the Test_2701
                  // Load test data

                  object sender = null;
                  System.EventArgs e = null;

                  this.arTimers.Add( new clsTimer(name,interval*60000,false) );
                  ((clsTimer) arTimers[0]).Tick += new System.EventHandler(this.LoadTestData());
                  ((clsTimer) arTimers[0]).Start();
                  
}

When I build the project, it points to the line, ((clsTimer) arTimers[0]).Tick += new System.EventHandler(this.LoadTestData()); , and says "Method name expected".
Am I just setting this up wrong?  Let me know if you need more information.  Thank you.

0
Comment
Question by:jvalescu
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Expert1701 earned 500 total points
ID: 17830363
Remove the brackets, and it should work:

  ((clsTimer) arTimers[0]).Tick += new System.EventHandler(this.LoadTestData);
0
 

Author Comment

by:jvalescu
ID: 17830377
Thank you.  It would have taken me another 8 hours to figure that out!
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17830383
You're welcome!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now