Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C language IDE – Compilers installation 14 68
Writing a parser for java language 4 71
FMX StringGrid1->Canvas->FillRect Problem 3 129
object oriented programming comparison 5 57
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 how to clear a vector as well as how to detect empty vectors in C++.

863 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

21 Experts available now in Live!

Get 1:1 Help Now