views:

142

answers:

2

I have a windows mobile application I have noticed that it properly terminate on exiting, they simply minimize and take up memory. I need to cehck whether any instance of the same application is running in the taskmanager.If exists, i need to kill the process.

I need to write small app that would loop through all open application processes and terminate the required one. Does such an application exist? If not, which onecould I use to write my own app for it?

+1  A: 

Typically this is not how you solve this problem.

You should hold a 'mutex' in your application, and when it launches a second time, you first check this mutex, and if it's taken, you know your app is already running.

Find an appropriate global mutex to hold, and then check for it (I'm not sure what sort you can use on whatever version of Windows Mobile you are targetting, but a trivial search should help you find the answer).

Noon Silk
I would argue that you need to figure out why the process is not closing correctly...
Jaco Pretorius
Jaco: It's just the default behaviour on Windows Mobile; clicking the 'X' minimises the app.
Noon Silk
Oh, then your answer is the correct one I recon
Jaco Pretorius
+1  A: 
  1. If your app shows an [X] in the corner that's a Minimize button. Change the MinimizeButton property of the form and it will become an [ok] button which will close it.
  2. The CF under Windows Mobile already enforces application singleton behavior. If the app is already running, the CF will look for it, find it, and bring it to the fore for you. No extra work needed.
  3. If you really want to find the process and terminate it, that's done with the toolhelp API set. You can P/Invoke it or use the classes in the Smart Device Framework.
ctacke