I have created a windows service which is currently having three timers. First timer is waking up every 15 sec, second timer is waking every min. and the third timer is waking everyday.
THe problem is these are spawning new threads every time and one time the threadpool gets used up completely.Is ther any to just spawn 3 threads and not spawn any more new threads.
My code looks something like this:
protected Onstart()
{
var timer1 = new TImer();
timer.Elapsed += Event1;
timer1.interval = 60000;
timer1.start();
var timer2 = new TImer();
timer2.Elapsed += Event2;
timer2.interval = 60000;
timer2.start();
}
private Event1(object,elapsedeventargs)
{
var workerthread1 = **new thread**(workerthreadfunc1)
workerthread1.start();
}
private Event2(object,elapsedeventargs)
{
var workerthread2 = **new thread**(workerthreadfunc2)
workerthread2.start();
}
So as you can see it is creating new threads which will use up all the threads in threadpool at some point and stops the windows service abruptly. Currently it is stopping and loogging a evet log with event ID 5000.