我遇到了創建連續計時器的麻煩。在定時器上創建的多重交錯線程將運行一段時間,然後完全停止。我允許的最大線程數是5,計時器間隔設置爲10000.因此理論上每2秒執行一個線程。System.Threading.Timer不連續
這發生了一段時間,但它然後停止。目前我正在測試控制檯應用程序並將回覆寫入應用程序。
我並不確切知道所發生的事情在這裏
internal class EngineThreadGenerator
{
private readonly AutoResetEvent _autoEvent;
private readonly Action<string, string> _processQueueDelegate;
private readonly Action<string, string> _purgeQueueDelegate;
private void createAllowedEmailThreads()
{
for (int counter = 0; counter < AppSettings.ProcessQueueAllowedThreads; counter++)
{
EmailThread _emailThread = new EmailThread(_collection, _processQueueDelegate, _purgeQueueDelegate);
TimerCallback _timerCallback = _emailThread.InitEmailThread;
Timer _stateTimer = new Timer(_timerCallback, _autoEvent, 0, AppSettings.ProcessIntervalInMilliseconds);
pauseLoop();
}
}
這裏任何幫助,不勝感激!乾杯!
你是說線程產卵停止,或線程本身停止? 「一段時間」有多久? – 2011-05-05 18:17:30
Threads itselve,通常他們在進程中停留3分鐘。 – BoredOfBinary 2011-05-05 18:49:09