Solved

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

Posted on 2002-04-16
2
249 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

839 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