Solved

URGENT - Need help with timer event handler

Posted on 2006-10-29
3
255 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Injector with Web Service 4 55
What namespace do I need to import? 2 38
IEnumerable<T> to a List<T> 8 40
How to repeat the data 4 18
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…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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 …

828 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