Where is Application.DoEvents()?
Hi,
Why there is no DoEvents method in System.Windows.Application class? How could I let the application do what it needs to?
Jan
Answers
Dear Jan,
You can try implementing your own Application.DoEvents() logic. I had read an interesting post about Application.DoEvents() some time back over here.
HTH,
Suprotim Agarwal
All Replies
Hello Suprotim,
thank you for answer. However, I believe that the described approach pushes the tasks in the background thread. Actually I don't want to return until things are finished.
Or did I misunderstand?
Jan
Dear Jan,
You can try implementing your own Application.DoEvents() logic. I had read an interesting post about Application.DoEvents() some time back over here.
HTH,
Suprotim Agarwal
That's a really interesting post. I'd recommend everybody interested in DoEvents() to read both.
I've tried to use Dispatcher.BeginInvoke(DispatcherPriority.Background), but it still executed before I expected - so the things I want to let execute seems to be on another thread. I've tried DispatcherPriority.ApplicationIdle, and although it succeeds time to time, it isn't anything extra.
Thread.Sleep(100) worked everytime I tried, so I am not sure if its simplicity is more than its dirtiness. (?)
For those interested what I'm trying to wait for is the HasVideo property updated after setting MediaElement.Source to null.
Jan
This DoEvents approach worked for me: http://shevaspace.spaces.live.com/blog/cns!FD9A0F1F8DD06954!411.entry
I used it as a blocking call here, check out the last function in the article: http://www.codeproject.com/WPF/UnitTestDispatcherTimer.asp
It worked like a charm, but I used it in a unit testing context. Not so sure I'd be happy to include a call to DoEvents in production code...
Hi Josh.
Thank you for the link to your article. It's quite advanced and it will take me a while to get through the stuff behind. :-)
Neither I like the DoEvents thing in production code, so I tend to leave the Thread.Sleep call here while it does the job. At least no earthquakes.

Jan
PS: I've tried the DoEvents method from DispatcherHelper and the behaviour I get is similar to Dispatcher.BeginInvoke(ApplicationIdle), that is, once it suffices, but usually not.


