views:

100

answers:

2

I'm using c# to write a windows form which installs and deploys WSPs to a sharepoint server. The problem I am having is that when I detect a problem and quit the application or when the cross in the top right of the form is pressed the form closes but the task is still in the process list.

My quit code is:

this.close();
application.quit();

The way i change between forms is:

form2.show();
form1.hide();

My only guess so far is that I use a few background workers, possibly these are not being terminated at the same time?

Thanks

+3  A: 

The process terminates when all threads that are not set as background threads terminate.

BackgroundWorker internally calls BeginInvoke on a delegate and that causes the code to be run a thread from the ThreadPool. The ThreadPool threads have IsBackground set to true, so it should not cause the application to hang. It is unlikely that a BackgroundWorker is causing the problem.

More likely, you have a place in your code where you are manually creating a new thread using new Thread() or similar and you have not set this thread's IsBackground member to true.

Mark Byers
I have not used any threads directly, just background workers unfortunately, It doesn't happen when debugging if i press "stop debugging" only when run standalone, the windows all shut but the process is still there!
Nathan
Do you use any COM components or do any integration with Office, e.g. Excel or Word? Do you have any 3rd party components that might be playing up?
Mark Byers
+1  A: 

It should be pretty easy to attach a debugger (you can get the Managed Stack Explorer if you don't have a debugger on the machine exhibiting the problem) and you can break into the process to see which threads are currently executing. In Visual Studio you should look in the Threads window and find one that's executing your code. Double click it, then look in the Call Stack window to see what's holding things up.

Josh Einstein