WPF: refresh a window during processing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy

    WPF: refresh a window during processing

    In other languages I've worked with, there is a way to allow an app to go
    idle just long enough for its windows to refresh. Can't find this in c#. I
    did find some discussion of multithreading the app, but that seems like a
    bunch of work to retrofit, given that I'd have to learn how to do it. Am I
    missing something?

    Jeremy

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: refresh a window during processing

    Jeremy,

    The best approach here is to use multithreading, as you have seen in
    other threads. You will want to perform your work on another thread, and
    then update the UI thread from the worker thread. Using something like
    DoEvents (which is for windows forms, not for WPF, I am not sure if WPF has
    an analogy) is just bad practice, and can introduce race conditions that are
    unexpected if not accounted for.

    In WPF, you would use the Dispatcher class to send notifications to the
    UI thread.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Jeremy" <jeremy-nospam@ninproda ta.comwrote in message
    news:OdOU$HRxIH A.1980@TK2MSFTN GP02.phx.gbl...
    In other languages I've worked with, there is a way to allow an app to go
    idle just long enough for its windows to refresh. Can't find this in c#.
    I did find some discussion of multithreading the app, but that seems like
    a bunch of work to retrofit, given that I'd have to learn how to do it.
    Am I missing something?
    >
    Jeremy

    Comment

    • Chris Jobson

      #3
      Re: refresh a window during processing

      In other languages I've worked with, there is a way to allow an app to go
      idle just long enough for its windows to refresh. Can't find this in c#.
      I did find some discussion of multithreading the app, but that seems like
      a bunch of work to retrofit, given that I'd have to learn how to do it.
      Am I missing something?
      Try this:

      void DoEvents()
      {
      DispatcherFrame f = new DispatcherFrame ();
      Dispatcher.Curr entDispatcher.B eginInvoke(Disp atcherPriority. Background,
      (SendOrPostCall back)delegate(o bject arg)
      {
      DispatcherFrame fr = arg as DispatcherFrame ;
      fr.Continue = false;
      }, f);
      Dispatcher.Push Frame(f);
      }

      But beware that this can give you problems with re-entrancy (just as VB6's
      DoEvents could).

      Chris Jobson


      Comment

      Working...