Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top