質問

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.

役に立ちましたか?

解決

There are several ways your "monitoring" app could work (and certainly more than I list here).

  1. 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.
  2. 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.
  3. 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.
  4. 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
  5. Use a window handle. The monitor app periodically P/Invokes GetWindow of FindWindow 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.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top