I have a windows form with a label, and a system.net timer called aTimer
.
The timer is created in an external class like this:
// Create a timer with a 3 minute interval.
common.aTimer = new System.Timers.Timer(3000);
// Hook up the Elapsed event for the timer.
common.aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 3 minutes (180000 milliseconds).
common.aTimer.Interval = 180000; // 3000; //
common.aTimer.Enabled = true;
mTimerRunning = true;
and in my form I run the code OnTimedEvent
to kick off a background worker
I want to show on my label the number of seconds before the next action is taken.
I tried this but it won't compile:
lblStatus.BeginInvoke(new Action(() =>
{
lblStatus.Text = "timer running - Check inbox in " & common.aTimer.Interval - common.aTimer.Elapsed & " seconds!";
}));
I have a compile error The event 'System.Timers.Timer.Elapsed' can only appear on the left hand side of += or -=
So what is the correct way to do this?
Ideally every tick of the timer I would update the label to show when the nxt run will happen.