CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
Go Back  Xtreme Visual Basic Talk > > > CoWaitForMultipleHandles - How to use it?


Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2010, 07:47 AM
Jellio Jellio is offline
Regular
 
Join Date: Nov 2009
Posts: 56
Default CoWaitForMultipleHandles - How to use it?


I'm working on a sports simulation/management game, and the game needs to do some lengthy operations every now and then. I had no problems with this in WinForms, and even though the app did get unresponsive at times, I never got any error and it always got through with the operation eventually. I have now moved my game over to WPF, and suddenly I get error messages like this every now and then:

"...The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations."

So, how do I actually use this CoWaitForMultipleHandles, because I had no luck searching for it on the web.
Reply With Quote
  #2  
Old 04-08-2010, 08:51 AM
AtmaWeapon's Avatar
AtmaWeaponCoWaitForMultipleHandles - How to use it? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Here's a more natural version of the error message.
Quote:
A fly has made it into your home. Flies can spread disease and are generally a nuisance. To solve the problem, you should use a heavy object (such as a truck) to crush the fly.
Does it sound sane? I hope not.

The real problem is the error message is at the wrong level of abstraction. It's clearly a COM-oriented message; it should be talking in terms of WPF. Referencing the example it should be saying, "There is a fly in the house; you should smack it!" You could probably use CoWaitForMultipleHandles() to solve the problem, but you'd likely end up writing a ton of COM interop code and that's just silly.

Here's what it probably should have said:
Quote:
The main dispatcher thread seems to be performing a long-running task. This thread is responsible for responding to user input and drawing. If you occupy the main thread with a long-running task, your application may appear unresponsive. Consider moving this operation to a background thread or find a way to allow the dispatcher thread to process messages.
You can probably ignore the error safely (unless it's crashing the application I guess.) But if you plan to ever let anyone else use the application, you should strive to *never* let your application be unresponsive. I'm very experienced at solving this problem in WinForms (it's my favorite topic of discussion and one of the few things I will boast as an area of expertise) but have only dabbled with it in WPF. This article looks very useful, and the technique discussed in the "Asynchronous Event-Based Model" section is one I'm very familiar with. The technique that uses the Dispatcher is probably more compatible with WPF application patterns, but either one is fine.

Keep one thing in mind as you work with multiple threads: you cannot update a control from a worker thread. In WPF, this gets a bit more restrictive: you cannot update a DependencyObject from a thread that did not create it. Controls are dependency objects, and thus are subject to the rule; less evident is that you can't touch classes like DoubleAnimation from a worker thread. Use the Dispatcher class to marshall a delegate call to the UI thread before doing anything with dependency objects.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 04-08-2010, 03:05 PM
Jellio Jellio is offline
Regular
 
Join Date: Nov 2009
Posts: 56
Default

Quote:
Originally Posted by AtmaWeapon View Post
This article looks very useful, and the technique discussed in the "Asynchronous Event-Based Model" section is one I'm very familiar with. The technique that uses the Dispatcher is probably more compatible with WPF application patterns, but either one is fine.

Thanks for the link, that definitely looks useful.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it? CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
 
CoWaitForMultipleHandles - How to use it?
CoWaitForMultipleHandles - How to use it?
 
-->