C# Source Code: Re: Automatically setting the wait cursor for an application
[
Home
|
Contents
|
Search
|
Reply
|
Previous
| Next ]
C# Source Code
Re: Automatically setting the wait cursor for an application
By:
Michael Proepster
Email (spam proof):
Email the originator of this post
Date:
Wednesday, January 25, 2012
Hits:
449
Category:
Windows Forms/GUI/Controls
Article:
Hi, your feature looks very promising. Unfortunately, I encountered some side effect: In a completely unrelated part of my application, I use a WaitHandle to wait for some operation to complete. After I added the AutoWaitCursor, I encountered strange exceptions in that part. I see in the Debugger that the UI thread is executing code despite of blocking on the WaitHandle. To be precise: the WaitHandle.WaitOne method calls into the WinForms message queue, which in turn calls OnPaint on some of my Controls which in turn can cause calls that other part. In the end I have a reentrancy problem in my code. None of the code anticipates that it is called multiple times without the prior call having completed. (Note that there is nothing multithreaded, all is done by the UI thread) I found some article in msdn about this (which I am apparently not allowed to link here, title "Managed blocking" by cbrumme) Basically, it says that message pumping can occur while a STA thread is blocked. Now back to the AutoWaitCursor: it uses a background thread to call SendMessage and decide then whether the UI thread is busy. This causes the blocked UI thread to process paint messages and finally leads to my observed behavior. I was wondering whether anybody also encountered this and knows a solution. By the way, this also means that the AutoWaitCursor might not work properly while the UI thread is blocked on some Monitor or WaitHandle because it does process the "ping" message.
Terms and Conditions
Support this site
Download a trial version of the best FTP application on the internet