Application.DoEvents in a WPF class library

  • Thread starter Thread starter Sathyaish
  • Start date Start date
S

Sathyaish

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?
 
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 - SynchronizationContext.Current.Post or
SynchronizationContext.Current.Send.

Marc
 
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.DoEvents 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....
 
I have three buttons on the excel worksheet and these buttons are calling c# dll function. One button is running for a long time with while true loop. I have changed it to be thread.
So that The cursor in the excel changed to be "hand" icon so that I can click on any cells or another button. But when I do so, the excel hanged and closed and recover to another excel.

Do you have any solutions on this??
Is "From within a class library, you can do this either by
raising events (that the UI handles including thread-switching), or
via sync-context - SynchronizationContext.Current.Post or
SynchronizationContext.Current.Send." what you say??
What they are ??



Marc Gravell wrote:

Re: Application.DoEvents in a WPF class library
16-Nov-08

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 b
doing it on a worker thread, and talking to the UI thread fo
updates. From within a class library, you can do this either b
raising events (that the UI handles including thread-switching), o
via sync-context - SynchronizationContext.Current.Post o
SynchronizationContext.Current.Send

Marc

EggHeadCafe - Software Developer Portal of Choice
Updated: Production Exception Handling For Dummies 101
http://www.eggheadcafe.com/tutorial...5c-a3f5b2184aa5/updated-production-excep.aspx
 
Could you give me some sample code of my case??



Kitty Programmer wrote:

Multiple events in excel
09-Oct-09

I have three buttons on the excel worksheet and these buttons are calling c# dll function. One button is running for a long time with while true loop. I have changed it to be thread.
So that The cursor in the excel changed to be "hand" icon so that I can click on any cells or another button. But when I do so, the excel hanged and closed and recover to another excel.

Do you have any solutions on this??
Is "From within a class library, you can do this either by
raising events (that the UI handles including thread-switching), or
via sync-context - SynchronizationContext.Current.Post or
SynchronizationContext.Current.Send." what you say??
What they are ??

EggHeadCafe - Software Developer Portal of Choice
A Developer's Guide To SQL Server Profiler
http://www.eggheadcafe.com/tutorial...d8-ce1600d6db80/a-developers-guide-to-sq.aspx
 
I have three buttons on the excel worksheet and these buttons are
calling c# dll function. One button is running for a long time with
while true loop. I have changed it to be thread.
So that The cursor in the excel changed to be "hand" icon so that I can
click on any cells or another button. But when I do so, the excel hanged
and closed and recover to another excel.

Your problem is very specific to the use of Excel via the Office interop
API. You should find a forum specific to that API and ask your question
there.
 
Back
Top