我的Windows服务能够在Win XP中启动线程(启动ThreadStart委托),但在Win 2003 Server中它不能,它也不会引发异常...线程根本无法启动。Windows服务无法启动Win 2003服务器中的线程
我做了一个在(OnStart)事件处理程序中具有相同代码的测试Windows服务,它在Win XP和Win 2003 Server上工作,这让我发疯,我不知道我的原始服务有什么问题,为什么它不能启动线程。
这里是我的两个服务取胜的问题,并在测试服务赢得了代码工作就好了:
private Thread trd;
StreamWriter sw;
int i = 0;
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
sw = new StreamWriter("c:\\TestingService.txt", true);
trd = new Thread(new ThreadStart(this.LoopingThread));
trd.IsBackground = false;
trd.Priority = ThreadPriority.Highest;
trd.Start();
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
}
private void LoopingThread()
{
while (i < 100)
{
lock (sw)
{
sw.WriteLine("hello from thread i="+i.ToString());
sw.Flush();
}
i++;
Thread.Sleep(1000);
}
}
这个代码是在两个服务取胜“正是”相同。 我原来的服务(有问题)得到了其他DLL多次提到,其“使用”列表是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Xml;
using System.Security.Principal;
using System.Reflection;
using System.Threading;
using System.Management;
和其他using语句是相关的一些机密的DLL(第三方) 但我我实际上并没有创建任何对象......有效的代码就是我发布的内容。
我无法弄清楚,为什么我的服务赢得不能在2003年赢得服务器启动线程
什么是在事件日志中为此?它会给我们更多的线索来帮助你 – AutomatedTester 2009-11-12 08:17:20
我有点困惑 - 你是说你发布的代码本身工作正常(在Win2003上),但是当你添加引用到第三方(和其他DLL)和使用语句显示它停止工作? – 2009-11-12 08:35:46