Cursor.Current=Cursors.WaitCursor works halfway through

  • Thread starter Thread starter Tsviatko Yovtchev
  • Start date Start date
T

Tsviatko Yovtchev

I am using the

Cursor.Current=Cursors.WaitCursor;

statement in my GUI thread to show the busy cursor. Then I am starting a
worker thread to fill a TreeView control from a database.

At the moment my worker thread starts the busy cursor, although
displayed, does not prevent the application controls from reacting to
user input. Moreover, oftentimes the busy cursor simply vanishes once
the worker thread starts.

I cannot find a reasonable explanation for this behavior. Help? Anyone?
 
It just got even more confusing. I commented out everything else but the
InitializeComponent() call in the constructor of my main form. Then I am
showing a Wait Cursor using

Cursor.Current=Cursors.WaitCursor;

as a response to clicking a button. The cursor displays but it does not
prevent the form controls from listening to mouse events.

Now, I thought that was what the Wait Cursor was supposed to do. I even
think I used it successfully once. But maybe I am wrong.

So, is the Cursors.WaitCursor supposed to make the app stop listening to
mouse events while displayed?
 
No, the wait cursor is just that - a cursor. It has nothing to do with
inputs. If you want input to stop, you must handle that.

-Chris
 
Uhm...this is in the description of the Cursor.Current in the MSDN -

"Setting the Current property changes the cursor currently displayed,
and the application stops listening for mouse events. For example, you
might set the Current property to Cursors.WaitCursor before you start
filling a TreeView, DataGrid, or ListBox control with a large amount of
data. After the loop is completed, set this property back to
Cursors.Default to display the appropriate cursor for each control."

And I am certain now that before I have used the WaitCursor to make the
app stop responding while filling a TreeView.
 
I would say that documentation is incorrect or meant for the desktop.

I guess there is some truth in it with regards to running a busy process
that runs within the UI thread
which renders the UI unresponsive.

BTW: You shouldn't set the cursor in your worker thread, you should be using
the UI thread for this. CF is less forgiving than the desktop with regards
to multithreading programming.
 
Back
Top