Threads and the cursor - resolved

Machaira

Junior Contributor
Joined
Aug 19, 2002
Messages
325
Location
Abingdon, MD
I create a thread when my application starts which performs a query that returns a sizeable number of records. I'm running this in a separate thread to allow the user to use the features of the application that don't require this data. If the user invokes the feature that requires this data I display a message on the status bar and attempt to set the mouse cursor, as follows:
Visual Basic:
Cursor.Current = Cursors.WaitCursor

DirectCast(Me.ParentForm, MainForm).StatusMsg("Loading commands, please wait...", False)

If tCommandListFormLoadThread.ThreadState = Threading.ThreadState.Running Then

    tCommandListFormLoadThread.Priority = Threading.ThreadPriority.Highest

    While tCommandListFormLoadThread.ThreadState = Threading.ThreadState.Running
        Application.DoEvents()
    End While
End If

Cursor.Current = Cursors.Default
The only problem is the cursor does not change. :) Any suggestions as to why this might be occuring would be appreciated.

[edit]I missed some info in the Help concerning calling DoEvents. :)
[/edit]
 
One thing that stands out is that you don't need the IF line because you're already doing the While loop.

And put a Doevents after the WaitCursor line.
 
The If line is there to set the priority of the thread before entering the loop. As for the DoEvents, that was the problem. Calling DoEvents resets the cursor to the default.

Thanks, though.
 
"DoEvents resets the cursor to the default"

Oh, I can't figure out why.
Just to test, place the cursor line in the loop.
 
Back
Top