Original post: How to access a timer from another class in C#
I tried everything.
-Event
-Invoke can\'t be done,because Timers don\'
Just because System.Windows.Forms.Timer doesn't have the ability to invoke, doesn't mean that your form doesn't. Try my InvokeEx from the second (or other) thread to enable the timer.
public static class ControlExtensions
{
public static TResult InvokeEx(this TControl control,
Func func)
where TControl : Control
{
if (control.InvokeRequired)
{
return (TResult)control.Invoke(func, control);
}
else
{
return func(control);
}
}
}
With this, the following code worked for me:
new Thread(() =>
{
Thread.Sleep(1000);
this.InvokeEx(f => f.timer1.Enabled = true);
}).Start();
And the timer instantly sprung to life after the 1 second.