Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SetCurrentDirectory path limit 7 122
Would like to move button in a function 3 77
mixing C++ & C# in Vis Studio 2013 7 178
No module found pypyodbc, 3 20
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

831 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