I am working on an (console) application, which should be executed on startup and keeps running all the time in the background (executing something every 30 minutes).
How can I, in another (device) application, check if my console application is running (and start it if its not)?
I am using VB.NET CF 2.0
and everything is being deployed on a device running WM 6.5
All the code examples I found where only available on the "standard" .NET.
Asked
Active
Viewed 1,669 times
0
-
I have no real knowledge of this Compact Framework but in the normal one I used a Mutex for my application. On the start I would register the mutex like `Private mutexProgram As New Threading.Mutex(True, "Global\" + "MyApp-{4512,1253,737,2323,2535B}")` (some random numbers there) and on the start of my app I check for this mutex like `Dim MutexExists As Boolean = True Try Dim m As Threading.Mutex = Threading.Mutex.OpenExisting("Global\" + "MyApp-{4512,1253,737,2323,2535B}") Catch MutexExists = False End Try` – Jens Jan 02 '14 at 10:14
-
I don't know if this works for your problem so I didn't post it as an answer, but it might be worth checking out for you. – Jens Jan 02 '14 at 10:15
-
Could you maybe elaborate a bit more? Like, what are those "random numbers"? And it seems that when creatign a new mutex, the only paramter I can give it is a boolean (seems to be available in .NET 4.5) – seph Jan 02 '14 at 11:02
-
1The Mutex object is somehow used for Thread syncronisation (I'm not an expert in any way so I don't know this stuff very well). The numbers there are just part of the Mutex's name which should be unique for your application (see MSDN here http://msdn.microsoft.com/en-us/library/f55ddskf%28v=vs.100%29.aspx ). The second part basically tries to open the Mutex object from the second instance of your program. If it exists it means the application is already running and you can act accordingly. If it does not exist it throws an exception and you know the application is not running. – Jens Jan 02 '14 at 11:42
-
I found that this is probably no way for you. See here: http://stackoverflow.com/questions/7679361/what-is-the-use-for-a-mutex-if-you-cant-name-it – Jens Jan 02 '14 at 11:45
1 Answers
1
There are several ways your "monitoring" app could work (and certainly more than I list here).
- Use a named mutex (you'll have to P/Invoke it). The monitored app would create and hold it, and the monitoring app would periodically check to make sure it's held. If it's not held, the monitored app is no longer running.
- Use the Toolhelp APIs. Have the monitoring app use the Toolhelp APIs to periodically enumerate the running processes. If the monitored app is not in the process list, it is not running.
- Use a named event. The monitored app would have a background thread that periodically sets a named (watchdog) event. The monitoring app would wait on that event and if it fails to get the event in a certain time bound, the other app is either not running or has locked up.
- Use a socket. Have the monitored app open a socket and listen on it. The monitor app would send a "ping" periodically to the monitored app. The monitored app would respond to the ping with an ack. If the monitoring app doesn't get an ack, the monitored app is either not running or is locked up
- Use a window handle. The monitor app periodically P/Invokes
GetWindow
ofFindWindow
to find an always-present window in the monitored app - often by Form text. If the monitoring app can't find the Window, the monitored app is not running.

ctacke
- 66,480
- 18
- 94
- 155