Application.DoEvents in a WPF class library

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

    Application.DoEvents in a WPF class library

    From inside a class library, in a WPF application, I wish to get a
    handle to an object, any object, may be the System.Windows. Application
    object that supports a method such as DoEvents() by calling which, I
    can force the control to yeild to the operating system so that the UI
    thread is not blocked, and the dispatcher is not suspended.

    Can you please help?
  • Marc Gravell

    #2
    Re: Application.DoE vents in a WPF class library

    First, DoEvents is a Bad Thing. Don't use it if you don't have to.
    Which is never ;-p. If you have something long-running, you should be
    doing it on a worker thread, and talking to the UI thread for
    updates. From within a class library, you can do this either by
    raising events (that the UI handles including thread-switching), or
    via sync-context - Synchronization Context.Current .Post or
    Synchronization Context.Current .Send.

    Marc

    Comment

    • Family Tree Mike

      #3
      Re: Application.DoE vents in a WPF class library

      I thought that Application was the only object in .Net that supported
      ..DoEvents(). You could use reflection to find any class in an assembly that
      has a method named DoEvents, but of course you would not necessarily know
      what that DoEvents does. Then again, if SomeObj.DoEvent s does what you want
      it to do, then as Marc points out, you shouldn't do it.

      Somehow that last paragraph seems to be among my more poetic ever....

      "Sathyaish" <sathyaish@gmai l.comwrote in message
      news:bb336bca-2b97-47aa-98d9-9f090a273bb8@d1 0g2000pra.googl egroups.com...
      From inside a class library, in a WPF application, I wish to get a
      handle to an object, any object, may be the System.Windows. Application
      object that supports a method such as DoEvents() by calling which, I
      can force the control to yeild to the operating system so that the UI
      thread is not blocked, and the dispatcher is not suspended.
      >
      Can you please help?

      Comment

      • Peter Duniho

        #4
        Re: Application.DoE vents in a WPF class library

        On Sun, 16 Nov 2008 01:02:47 -0800, Sathyaish <sathyaish@gmai l.comwrote:
        From inside a class library, in a WPF application, I wish to get a
        handle to an object, any object, may be the System.Windows. Application
        object that supports a method such as DoEvents() by calling which, I
        can force the control to yeild to the operating system so that the UI
        thread is not blocked, and the dispatcher is not suspended.
        >
        Can you please help?
        In WPF, just as in the Forms namespace, there is just one way to
        accomplish this. WPF has an event dispatcher class, and there's a method
        to allow explicit and immediate processing of events currently in the
        queue. If you just search MSDN for "WPF" and "event dispatch", it seems
        likely you'd find it.

        But, as Marc and Mike point out, this sort of programming style is really
        not a good idea. One of the most problematic issues is that it introduces
        a re-entrancy into a code base that was never designed for re-entrancy to
        occur. Much of the time this won't matter, but when it does it will
        create bugs that are difficult to find and fix. You're better off just
        doing the extra effort to correctly implement time-consuming tasks on a
        different thread.

        Pete

        Comment

        Working...