views:

520

answers:

1

I want the user to simply be able to exit my application. However, for some reason, code which I have on a time delay, controlled by a stopwatch, is still trying to execute. I do not care if it tries to do so or not, but I want to stop the error and force-quit the application, terminating ALL running threads where they stand.

I am using Visual Basic Express 2008 with SP1, and I am coding in vb.net, this is a WinForm application.

I have tried simply closing the forms with Formname.Close() and I also tried Application.Exit(). I even tried an If Then statement which exited the thread which referenced my textbox, quitting it with Application.ExitThread()

I got:

ObjectDisposedException was unhandled

Cannot access a disposed object. Object name: 'TextBox'.

How can I handle this exception or simply finish exiting?

Thanks for the help!

EDIT: To clarify, I don't care how this is achieved, I just want the application to stop running, and have no errors occur.

+1  A: 

can you shut off the stopwatch before you exit?

Beth
The stopwatch is declared from within a subroutine, it had already stopped by the time the ObjectDisposedException occurred.
Cyclone
There may be something else going on. Try deleting your text box and/or your stopwatch and see if it exits w/o error. Try to isolate which object/condition is causing the problem.
Beth
It is still executing the code "LoadBox.AppendText(LoadProgress.Text + Environment.NewLine)" when it has already executed. How do I stop this?
Cyclone
Eh, I solved my problem. I simply removed the ability to quit the application at that point in time. It was a two-second process anyway, if they can't be patient for that then that stinks for them ;).
Cyclone
glad you fixed it. sometimes the problem is simply that you're looking in the wrong place.
Beth