Adwait

Adwait

  • NA
  • 8
  • 0

Process lingering around after application quit

Aug 15 2007 3:20 PM
When I run my windows application, a main form is loaded. I then fire another thread which keeps scanning for some RFIDs. When the RFID scanning is done I stop the process by simply setting a boolean variable to true. So that later I can resume it when needed.
Soemthing like
while(!StopThread)
{
.... my thread code
}

When someone clicks Alt + F4 on the main window, the form closes down. But I still have a process running in my task manager. This has to do with the thread that I fired because if I disable it, the application shuts down clean.

Here is what I tried and did not work.

1. I set the boolean variable to true so that the thread function stopes. I then tried calling m_workerThread.Abort() and handled a excetion for ThreadAbortException. Then in the finally block I put m_workerThread.Join(). I also tried removing the join.
2. In the dispose of the main form, I tried to do a getprocessbyname and kill that process if its running. That did not work either.

Can someone please tell me why would this be happening and whats the clean way to solve this problem ?
Adwait

Answers (5)