Ask a questionAsk a question
 

AnswerWhere is Application.DoEvents()?

  • Tuesday, August 21, 2007 3:13 PMJan Kučera Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Tuesday, August 21, 2007 4:51 PMSuprotim AgarwalMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Tuesday, August 21, 2007 3:29 PMSuprotim AgarwalMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Dear Jan,

     

    Check this post

     

    HTH,

    Suprotim Agarwal

     

  • Tuesday, August 21, 2007 4:32 PMJan Kučera Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Tuesday, August 21, 2007 4:51 PMSuprotim AgarwalMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

     

  • Tuesday, August 21, 2007 5:44 PMJan Kučera Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Tuesday, August 21, 2007 5:50 PMJosh SmithMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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...

  • Tuesday, August 21, 2007 6:16 PMJan Kučera Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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. Wink

     

    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.