Answered by:
Dispatcher causes NullReferenceException

Question
-
This line of code, which is run every 10 secs, normally updates my UI, and works perfectly.
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new UIUpdateDelegate(this.UIUpdate));
I have a regular file-menu with an exit option which runs Application.Current.Shutdown();
If I use the file => exit approach it works fine. However, if I close the application with the X button in the upper right corner,
the Dispatcher causes an unhandled nullreferenceexception, but not always.
Any ideas on what is happening?
http://www.catb.org/~esr/faqs/smart-questions.html#intro- Moved by Figo Fei Monday, August 25, 2008 8:51 AM redirect (Moved from Visual C# Language to Windows Presentation Foundation (WPF))
Friday, August 22, 2008 11:10 AM
Answers
-
Put a Null check:
if(this !=null)
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new UIUpdateDelegate(this.UIUpdate));- Proposed as answer by Marco Zhou Wednesday, August 27, 2008 10:10 AM
- Marked as answer by Marco Zhou Thursday, August 28, 2008 10:33 AM
Monday, August 25, 2008 1:07 PM
All replies
-
You'll need to post to the Windows Presentation Foundation forum.
Hans Passant.Sunday, August 24, 2008 4:24 PM -
My bad.
I'm giving this one a bump since I obviously posted in the wrong forum, and now it's far down the list :)
http://www.catb.org/~esr/faqs/smart-questions.html#introMonday, August 25, 2008 11:53 AM -
Put a Null check:
if(this !=null)
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new UIUpdateDelegate(this.UIUpdate));- Proposed as answer by Marco Zhou Wednesday, August 27, 2008 10:10 AM
- Marked as answer by Marco Zhou Thursday, August 28, 2008 10:33 AM
Monday, August 25, 2008 1:07 PM -
Ok, I'm trying that, thanks.
Why is that? The timer elapses during object disposal and the method is no longer available to run?
http://www.catb.org/~esr/faqs/smart-questions.html#introMonday, August 25, 2008 2:49 PM -
Event handling and dispose of objects are working in different threads, this is the only possibility.Tuesday, August 26, 2008 5:40 AM