Re: Ignoring Mouse Events During WaitCursor

From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 02/16/05


Date: Wed, 16 Feb 2005 15:30:34 +0200

Hi Karen,

Changing the shape of the mouse pointer has nothing to do with processing
mouse messages. Even when the mouse pointer is set to the hourglass, the
system still accumulates events received from the input devices (not only
the mouse, but also the keyboard and whatever device you can imagine). You
can probably forcibly clear the event queue with API calls upon the
completion of the task, but I'd consider it a hack and definitely a bad
programming style.

Why don't you use asynchronous delegates or multi-threading instead? This
way, the application won't be blocked while working on the long-running task
(that is, it will be able to repaint itself, the user will be able to
minimize and restore the window etc.), and at the same time you can disable
controls and menu items which shouldn't be available until the task
completes.

-- 
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"KarenP" <KarenP@discussions.microsoft.com> wrote in message 
news:07F8711A-D1F2-4BEB-B436-FCE8530BC212@microsoft.com...
> In my Windows Forms application, while executing a process that takes some
> time, I am changing the cursor to the hourglass by setting Cursor.Current 
> =
> Cursors.WaitCursor.
>
> This is working just fine, except that any mouse events generated during
> this wait period (such as clicking on a button, etc.), get processed once 
> the
> processing is complete.  For example, while waiting for my task to 
> complete,
> I click on a button (even though the cursor is an hourglass).  When the 
> task
> is complete, the button click event is executed.
>
> The documentation for the Cursor.Current property makes it sound like the
> application will stop listening for mouse events while the cursor is not 
> set
> to Cursors.Default, but this does not seem to be the case in practice.
>
> Any advice?  Is this a bug or am I doing something incorrectly?
>
> Thanks!
>
> -Karen