Solved

C#:  Catching an event from a timer in a class

Posted on 2002-04-16
2
253 Views
Last Modified: 2010-04-02
There needs to be a C# forum.

I have created a class in which I need a timer.  Something like this;

public class myClass
{
  public System.Windows.Forms.Timer  myTimer;
  myTimer = new System.Windows.Forms.Timer();
  myTimer.interval = 1000;
  myTimer.enabled = true;
}

How do I now catch that tick event?

This timer isn't a form anywhere so I created it dynamically..  This works as it does in delphi but damn if I know how to catch that event.

A timer I dropped on my form just for testing purposes gave me an event like this;

private void myTimer_tick(object sender, System.EventArgs e)
{
  // Do thing here
}

But somewhere I must attach myTimer to the myTimer_tick event..   How do I do this?  (This is probably very simple.. I'm new to C#..)
0
Comment
Question by:Palamedes
[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 Comments
 
LVL 4

Accepted Solution

by:
IainHere earned 100 total points
ID: 6945016
Looks like you missed the

myTimer.Start();

And to call your method when it ticks, use

/* Adds the event and the event handler for the method that will process the timer event to the timer. */
myTimer.Tick += new EventHandler(TimerEventProcessor);

Where TimerEventProcessor is the name of your function.  All taken from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsTimerClassTickTopic.asp
0
 
LVL 4

Author Comment

by:Palamedes
ID: 6945479
That did the trick!   Thanks a bunch..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

729 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