Reputation: 616
I am doing windows service to check another exe is running or not. If not running, I need to start this exe again. I use the timer to check every one minute. But Timer doesn't work.Please give me advice.Although the service is running, no code in timer is working. Thanks.
Upvotes: 0
Views: 290
Reputation: 31
The original poster has probably fixed this problem, but a very common mistake when it comes to Windows Services and Timers is to use the System.Windows.timer and not the System.Timers.Timer which is the one you shall use.
Just posting this in case someone else comes over this post and maybe this answer will help.
Upvotes: 2
Reputation: 266
Is it possible to wrap your service around the exe itself that way you can take advantage of the service being able to restart itself thus restart your exe?
I have done this with a WCF service but im sure it would be possible with any process. So onStart of the service run your exe and wrap it in a try catch. then if it fails just restart it. Also if the service fails itself you can get it to automatically restart (option available to all windows services).
Upvotes: 0
Reputation: 29322
We need the code to help you.
Which timer did you use? There are three and they all have a different way of working. Windows forms timer needs to be started or set to start on load if that is the one you've used.
Other timers have different properties but you might run into issues with the reference being garbage collected.
BUT
All that aside, it sounds like you want to implement your EXE as a service, that way if it crashed you can set windows to restart it for you. If you wrote the exe you're monitoring, I suggest you look into it.
EDIT: Also you may wish to look at SrvAny which will convert any executable into a windows service for you. Its part of the windows server resource kit.
Upvotes: 2