Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've developed a WCF service which I'd like to host as Windows service. Unfortunately my WCF service produce some memory leaks (it uses third-party components so I can't fix this). I'd like to have an ability to recycle a service time to time. Can I do it with windows service? I wouldn't like to move to IIS or WAS, as I want to host the service on XP machine.
Posted

I faced exactly the same problem once. I fixed it by running a batch file using Scheduled Tasks on a defined interval that stopped and restarted the service. I think it went something like this:

net stop [ServiceName Here]
net start [ServiceName Here]


It wasn't pretty, but it worked.
 
Share this answer
 
Comments
Igor Merabishvili 23-Feb-11 11:41am    
Thanks Jim,

if I can't find a better solution then I'll probably use this one.

Igor
Yusuf 25-Feb-11 11:58am    
of course this may help, but there are few caveat to it.
1. What if the service hangs before the next stop/start time?
2. What if the service stop/start fails in the schedules tasks?

We're faced with similar issue, we come up with a different solution. See my Answer for the solution.

BTW, +5 for your answer.
In windows service there is no notion of recycling. We had similar situation long time back. What we did was, we created service monitor. The service monitor was responsible for starting/stopping and recycling the main service.
 
Share this answer
 
Comments
Espen Harlinn 25-Feb-11 11:26am    
Good idea, my 5
Igor Merabishvili 28-Feb-11 10:28am    
Hi Yusuf,

may be you have somewhere the code sample as well (if it's not too much to ask ;)

Igor
Yusuf 28-Feb-11 11:35am    
This should be that hard to write, it is simply your service watchdog.

1. You need to check if the service is installed. See http://stackoverflow.com/questions/4554116/how-to-check-if-a-windows-service-is-installed-in-c
2. Get the status of your service. See http://stackoverflow.com/questions/178147/how-can-i-verify-if-a-windows-service-is-running
3. On some given time interval recycle your service.

That is all.
Igor Merabishvili 1-Mar-11 9:56am    
If it's just that then you are right. I thought about graceful restart, where the request kept by the monitor in the meantime and then delivered to the new instance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900