What would be possible way(s) to start non-blocking thread which then runs a few System.Timers.Timer based tasks? Working on writing this code a non-UI library. I
have seen similar questions and the advice on them have been to convert the library into
Windows Service – not sure if that is an option for me.
E.g., Process.Start() would implement non-blocking thread which instantiates and executes Timers based functions.
public void Start()
{
Timer t1 = new Timer(10000);
Timer t2 = new Timer(15000);
t1.Elapsed += new ElapsedEventHandler(T1Task);
t2.Elapsed += new ElapsedEventHandler(T2Task);
t1.Enabled = true;
t2.Enabled = true;
// the following is blocking, of course
while (true)
{
Thread.sleep(1000);
}
}
In code above, if the library call is invoked via WinForm, the GUI would obviously block.
Just use System.Threading.Timer. It’s non blocking and fires events on a non-UI thread.