Search code examples
c#sharepointformsprocessquit

quiting a c# application leaves it in memory


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


Solution

  • 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.