Solved

URGENT - Need help with timer event handler

Posted on 2006-10-29
3
250 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
Comment Utility
Remove the brackets, and it should work:

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

Author Comment

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

Expert Comment

by:Expert1701
Comment Utility
You're welcome!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

10 Experts available now in Live!

Get 1:1 Help Now