473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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?
Nov 16 '08 #1
3 8178
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
Nov 16 '08 #2
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....

"Sathyaish" <sa*******@gmail.comwrote in message
news:bb**********************************@d10g2000 pra.googlegroups.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?
Nov 16 '08 #3
On Sun, 16 Nov 2008 01:02:47 -0800, Sathyaish <sa*******@gmail.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
Nov 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: bazad | last post by:
Hi, I'd like to understand consequences of Application.DoEvents call. Does it create a new thread? Thank you
2
by: Bob lazarchik | last post by:
Hello: I have created a component in which I need to do a timeout operation. What is the equivalent to Application.DoEvents() in a Component. public virtual bool ReceiveResponse( out string...
6
by: Ollie Riches | last post by:
I understand the use of Application.DoEvents() to process all outstanding messages on the message queue in a winforms application if you have long running process on the UI thread. But can anyone...
5
by: Scupper | last post by:
Certain "Imports" of classes change the frame of reference within a class such that making calls to functions such as "Application.DoEvents()" and so on becomes ambiguous and gives a "Reference to...
0
by: Ralf Gedrat | last post by:
Hello! I have a Application, this throws after some time following exception: Item has already been added. Key in dictionary: "- 1" key being added: "- 1" I use Application.Run with...
1
by: RSH | last post by:
I created a new Windows Form project and I created a simple richtextbox to write to and I am looping through a simple example but obviously the screen isn't updated it only shows the first...
8
by: TrtnJohn | last post by:
I have an application where I would like to block waiting on an asynchronous event and still process messages. I can implement a hard loop to block such as: Do While StillWaiting...
13
by: Amjad | last post by:
Hi, Is there an equivalent to the "Application.Doevents" method in modules or Windows services? I want to make a Windows service that calls a DLL. The DLL would have all my functions and it...
5
by: james.jdunne | last post by:
System.ArgumentException: Item has already been added. Key in dictionary: "-1" Key being added: "-1" at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.