我在创建一个连续的计时器时遇到了问题。有多个错开的线程在定时器上创建,这些线程会运行一段时间,然后完全停止。我允许的最大线程数是5,计时器间隔设置为10000。因此理论上每2秒钟就会执行1个线程。
这种情况会持续一段时间,但之后就会停止。目前我正在测试控制台应用程序并将响应写入该应用程序。
我不确定这里到底发生了什么。
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();
}
}
非常感谢您的帮助!干杯!