我有一些代码,在我的电脑上安装/运行时按预期工作,我的电脑是Windows 7,但在其他服务器(2003和2008)上运行时却不行。这段代码来自一个.NET4 WCF服务库,我在Windows服务中使用它。这里是简化版。
public void monitorQueueAndDoStuff() {
MonitorRetryQueue();
MonitorMainQueue();
}
private void MonitorMainQueue() {
Log.Info("MonitorMainQueue called");
Task.Factory.StartNew(() =>
{
Log.Info("new thread monitoring queue");
// ...NMS stuff
while (!stopped) {
ITextMessage mess = null;
mess = blockingMessageCollection.Take();
sendToQueue(mess);
}
}
}
});
}
private void MonitorRetryQueue() {
Task.Factory.StartNew(() =>
{
//...NMS stuff
consumer.Listener += new MessageListener(OnRetryErrorMessage);
Log.Info("new thread monitoring second queue");
//need to be constantly up for the consumer to hang around
while (!stopped) {
Thread.Sleep(1000);
}
}
}
});
}
线程应该进入循环执行一些工作。主线程在BlockingCollection上进行阻塞。 现在,它创建了两个任务,但只进入了第二个,它从未在日志中打印“新线程监控队列”。我无法理解为什么不是这样。我尝试了远程调试,但由于它从未进入代码,所以我看不到任何有价值的东西。
我没有发现任何可以改变部署服务器上代码行为的东西。这里有人能够知道原因吗?Visual Studio项目中有任何设置吗?