Simple threading issue using windows service

I had not written Windows services before and thought everything was going fine until I deployed it to live. In dev, it works fine and it works fine, but as soon as it goes into production, it falls to its back after the first cycle.

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 executes the loop:

        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);

        }

Can anyone think why this will fall after it works for the first time? Am I doing something stupid?

This is the method causing the problem:

public static string GetXmlFromFeed (string strUrl) {var rssReq = WebRequest.Create (strUrl); var rep = rssReq.GetResponse (); returns a new StreamReader (rep.GetResponseStream ()). ReadToEnd (); }

In GetResponse ()

maybe a timeout and nothing to do with the stream at all, and

+3
1

, StartChecks , ( .NET 2.0, , ).

try/catch, .

+1

Source: https://habr.com/ru/post/1763301/


All Articles