我以前没有写过Windows服务,在我将其部署到Live之前,我认为一切都很顺利。在dev中,它工作得很好,轮询也很好,但是一旦投入生产,它就会在第一个循环之后落在后面。
The exception I recieve is:
Application: ProgramName.WinService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Exception
Stack:
at ProgramName.WinService.UpdateChecker.StartChecks()
at ProgramName.WinService.UpdateChecker.StartPolling()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
下面是执行循环的代码:
private readonly Thread pollingThread;
public UpdateChecker()
{
pollingThread = new Thread(StartPolling);
InitializeComponent();
}
protected override void OnStart(string[] args)
{
pollingThread.Start();
}
protected override void OnStop()
{
pollingThread.Abort();
}
protected void StartPolling()
{
do
{
StartChecks();
Thread.Sleep(10000);
} while (true);
}
有人知道为什么它在第一次运行后会崩溃吗?我在做傻事吗?
这是导致问题的方法:
公共静态字符串getxmlfromfeed(字符串strurl)
{
var rssreq=webrequest.create(strurl);
var rep=rssreq.getResponse();
返回新的streamreader(rep.getResponseStream()).readToEnd();
}
在getResponse()上
可能是一个超时,与线程无关。