I'm developing a project on Visual Studio 2015 using C# and WPF. Sometimes I quit my running project with my close command, and sometimes with the stop debug button. The problem is that after a few tests, my PC starts to warm and the fans make noise. I have to quit Visual Studio to calm the machine.
So I have questions :
- How to see the threads not ended after a test ?
- When I know them, how to properly end them ? (actually I
Dispose
some threads whenWindowClosing
) - How make sure that thread will properly ends when I use the stop debug button ?
Thank you
EDIT:
There is the screenshot of task manager. When I start application the CPU rise from 5% to 15% (or event 25%). RAM rise from 4GO to 4.5. When I stop application, CPU goes to 45% for a few seconds and go back to 5% but RAM goes to 4.70GO and doesn't go back down.
EDIT2:
I founded this kind of thread on my application:
private bool isClosing = false;
public void Start()
{
isClosing = false;
ThreadPool.QueueUserWorkItem(new WaitCallback(doWorkThread));
}
public void Stop()
{
isClosing = true;
}
private AutoResetEvent endPoolStateButton = new AutoResetEvent(false);
private void doWorkThread(object sender)
{
Action action = new Action(() => doWork());
while (!isClosing)
{
Thread.Sleep(100);
this.Dispatcher.BeginInvoke(action, System.Windows.Threading.DispatcherPriority.Background);
}
endPoolStateButton.Set();
}
private void doWork()
{
/* Job performed */
}
I wonder if there is a really good way to use thread ? If application close without setting isClosing = true
the while never stop. And the thread is never really aborted ? Do you think that this kind of thread can cause all the troubles I have ?