When I run my Visual Studio Windows Forms application by clicking F5 (debug mode), after I click on the close button (which calls Application.Exit()), after a few seconds I get an error that says:
cannot acess a disposed object: Object name ‘SampleForm’.
A bit of background, I have another thread that runs every x seconds.
My guess is that when I close the application, and since it is still in debug mode, the other thread is still running and it tries to access something but since I close the application the form is disposed.
Is this correct?
Do I have to kill the background process thread in before I call Application.Exit()?
Update
Now when I call thread.Abort() before the call to Application.Exit() the application closes completely. Before, EVEN after I clicked on the close button, the debugger was still running (i.e. the stop button was not selected) so it must have been because the thread was still active).
Mark your thread as BackgroundThread, and it will stop running as soon as you close the window.