kill child process on restart of my windows  service

Posted on 2011-05-10
Medium Priority
Last Modified: 2012-06-21
I have created a windows service which fires another process (myprocess.exe) every 10 minutes, which creates files, prints them and exits. Sometimes when someone restarts the service while myprocess is still running, it does not kill the myprocess in the memory. The service starts another myprocess.exe, and now I see two instances of myprocess.exe in the task manager. Since both are trying to write to the same file, they clash and I get error.

How do I make my service kill myprocess.exe, if it is running when the service gets restarted.

Question by:patd1
  • 2

Accepted Solution

bartvd earned 2000 total points
ID: 35733145
You could check if the process myprocess.exe is running when the service restarts. If it exists, you could kill it.

Example: http://www.dreamincode.net/code/snippet1543.htm

Read the comments.

Author Comment

ID: 35737845
Thanks that was what I was thinking, but wanted to make sure if that is the right thing to do. Does it matter if I kill the myprocess onStop instead of onStart.

Thank You.

Expert Comment

ID: 35740060
It doesn't matter, but make sure you kill the process before you start the new process.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question