Domanda

I have a Windows service which should listen for HTTP requests. I am using HttpListener for this. The service is successfully do its job. However when the service is set to automatically start when system starts I have a delay in HTTP initialization. HttpListener constructor takes from 1 to 2 minutes to return. So the user is successfully logged in and for example his messenger is already online. I've read that HttpListener is using HTTP.SYS: kernel mode http listener, so may be it is normal since the system is initializing.

My questions are: 1) Is it normal that HttpListener has such delay in initialization? 2) Is there any workarounds to avoid such delay (except not using HttpListener)?

EDIT: Issue is not reproduced on Windows 7. I was only able to reproduce it on Windows XP machines.

È stato utile?

Soluzione

I've found workaround.

I was calling HttpListener constructor from service's "OnStart thread". If I move constructor call in another thread and just return from service's OnStart method, HttpListener initialized fast as usual.

I don't know why is it so. Can only suppose that some component which is needed by HttpListener is initialized subsequently later at system start up.

By the way, issue is not reproduced on Windows 7. I was only able to reproduce it on Windows XP machines.

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