Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

URGENT - Need help with timer event handler

Posted on 2006-10-29
3
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Expert1701 earned 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

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 article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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