By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Ignoring Mouse Events During WaitCursor

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <Ka****@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.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


Nov 16 '05 #2

P: n/a
Hi Dmitriy,

Thank you for your response. I guess I misunderstood the documentation for
Cursor.Current. I do plan on running my task asynchronously and will be sure
to disable any controls that should not be available while the task is
running.

Thanks again,

Karen
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.