2

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.

Cyclone
  • 17,939
  • 45
  • 124
  • 193

2 Answers2

2

The worst case scenario solution to your problem is:

Process.GetCurrentProcess.Kill()

Regards, Zibri

Zibri
  • 9,096
  • 3
  • 52
  • 44
1

can you shut off the stopwatch before you exit?

Beth
  • 9,531
  • 1
  • 24
  • 43
  • The stopwatch is declared from within a subroutine, it had already stopped by the time the ObjectDisposedException occurred. – Cyclone Aug 20 '09 at 17:59
  • 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 Aug 20 '09 at 18:28
  • It is still executing the code "LoadBox.AppendText(LoadProgress.Text + Environment.NewLine)" when it has already executed. How do I stop this? – Cyclone Aug 20 '09 at 18:44
  • 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 Aug 20 '09 at 18:56
  • glad you fixed it. sometimes the problem is simply that you're looking in the wrong place. – Beth Aug 20 '09 at 19:17