I am new to C#, and I needed to use a timer for a small application that I use for monitoring a piece of hardware. I found some reference code for timer, but it uses DoEvents(). Since, I run the timer for a long time, sometimes days and hours, I started getting stack overflow. I now understand that DoEvents() is causing this, and it is something most people recommend using. What feature would you recommend I use in place of DoEvents instead to setup my timer?
My code :
private void BeginMonitoringClick() {
{
myTimer.Tick += new EventHandler(TimerEventProcessor); // myTimer declared elsewhere
myTimer.Interval = 2000;
myTimer.Start();
while(!exitFlag)
{
Application.DoEvents();
}
}
private void TimerEventProcessor(Object myObject, EventArgs myEventArgs){
// Talk to hardware, see if it is doing OK
}