Reputation: 27275
My application generally running on 10-20 threads and these threads sending events to the GUI to the update certain controls almost every seconds.
When the user close the application middle of these, all updates related with these events causes several random crashes. Mostly ObjectDisposedException
and NullReferenceException
.
Since the events already thrown but not handled yet by the .NET Framework, they are not in a state where I can cancel them.
I'm not quite sure about the best way to handle this. Currently I'm just swallowing exceptions the exceptions.
Upvotes: 3
Views: 1015
Reputation: 123662
In addition to Marc Gravell's suggestions, here's a few more things:
Environment.HasShutdownStarted
before doing anything that could cause an ObjectDisposed
exception.IsDisposed
(all forms and controls have it)Upvotes: 1
Reputation: 1064044
A few options:
FormClosing
?), you could start cleanly exiting the threads (via a flag somewhere)Upvotes: 4