Hi all,
I havent written a windows service before and thought everything was going well until I deployed it to live. In dev it works fine and the polling it great, but as soon as it goes into production it falls on its backside after its first loop.
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()
and here is the code that is doing the looping:
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();
//10 seconds
Thread.Sleep(10000);
} while (true);
}
Does anyone have any idea why this would fall over after it runs the first time? am I doing something stupid?
This is the method causing the issue:
public static string GetXmlFromFeed(string strUrl) { var rssReq = WebRequest.Create(strUrl); var rep = rssReq.GetResponse(); return new StreamReader(rep.GetResponseStream()).ReadToEnd(); }
On the GetResponse()
possible a time out and nothing to do with the threading at all then