on some of our customers WinXP SP3 machines, theres a strange behaviour occuring nearly daily.

We've installed a windows service thats executing the following code on startup:

if( !HttpListener.IsSupported )
{
    throw new Exception( string.Format( "HttpListener is not supported on {0}.", Environment.OSVersion ) );
}

_httpListener = new HttpListener();
_httpListener.Prefixes.Add( "http://localhost:20001/" );

_thread = new Thread( new ThreadStart( StartListening ) );
_thread.Start();

Now sometimes when Windows starts, the code is throwing the "Not Supported" Exception. After stopping and starting the service again, the HttpListener works!

Are there any service dependencies my windows service needs?

有帮助吗?

解决方案

Found the solution!

In the ServiceInstaller constructor just add the following line:

serviceInstaller.ServicesDependedOn = new string[] { "HTTP" };

That makes your own Service dependend on the Windows HTTP Service and just starts when the HTTP Servive has successfully started.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top