SDF Sample: Stopping a windowless process you didn’t start

Problem A
I have an application that starts up a worker thread.  I have code that properly kills that thread during normal shutdown, but if I’m debugging and stop the app, the thread keeps the app alive and I can’t debug the app again without resetting teh device.  What can the SDF do for me?


Problem B
I have a CE device that is running a process without a window (console or otherwise) and I’d like to kill it.  What can the SDF do for me?


Solution
The solution to both is found in the OpenNETCF.ToolHelp.ProcessEntry class.  Add this to an app and run it.


ProcessEntry[] currentProcesses = ProcessEntry.GetProcesses();

foreach (ProcessEntry p in currentProcesses)
{
  if (p.ExeFile.ToLower() == “MyAppName.exe”.ToLower())
  {
    p.Kill();
    return;
  }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s