1

I have made a windows desktop application (.net). At one point in running my installed version, the application became unresponsive. So I tried to end it in Task Manager, and it popped up with that "End Now" button which I clicked, but my application didn't die. I tried killing it in the Processes tab of Task Manager - didn't die then, either. So then I even got Process Explorer and tried killing it there - that didn't even kill it. I finally resorted to restarting my computer.

So I'm wondering if there is anything I can / should do in my application that will prevent that from happening? If it does get hung up and stops responding, is there a way to ensure it will die if killed in Task Manager?

Andy
  • 616
  • 11
  • 32

1 Answers1

0

Notes on debugging and the problem itself:

Why it hangs could be too complicated to answer because generally a process not ending means something went wrong in an unexpected way and might not repeat. If it does every time you run, step through your code to identify where it hangs. All tasks should, in theory, be "endable" the way you tried. Since they aren't always, you might actually need a stronger way to kill them.

When doing something like long running device IO, you could wind up in places where the UI is freezing on things that are simply taking too much time. To be safer, start using a background thread. If you go that route, Stackoverflow already has a ton of answers to that (separate) type of question. The one I looked at just now is titled "WinForm Application UI Hangs during Long-Running Operation"

Killing it:

You can try using taskill from an elevated command prompt. To elevate the command prompt, right click and 'Run as Administrator'. (More detail in the link.)

To use taskill, the format is: taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t]

If the PID of the process is 123, run taskill /pid 123.

If you can't see PID, go to: View (menu) > Select Columns (a menu item). From there you can check the box for PID.

You can try a free tool from Microsoft called PSTools, but I've never had to resort to that. If I can't kill it with an elevated command prompt, I reboot.

Community
  • 1
  • 1
Palu Macil
  • 1,708
  • 1
  • 24
  • 34
  • that is good to know about taskkill in an elevated command prompt...I'll try that next time if it happens again. Though this does not happen every time. This one time it happened after having an issue transferring data from a device. This particular issue is caught, and other times when that's happened I've been able to move on (the application did not hang up)...so it's not consistent. – Andy Jul 10 '15 at 15:40
  • @Andarta I updated my answer to include a suggestion on the debugging. You have a few options to place IO somewhere it won't freeze the UI, but since that question is a bit different than this one, I linked to a question that applies. The answer accepted is worth a read. – Palu Macil Jul 10 '15 at 15:53