Application.DoEvent and wait cursor

T

TF

Hi,
I am writing a Windows Application in C#. I want to show wait cursor
while any form control is updated (e.g. ComboBox list is filled) which
takes some time. It works fine when i do like:

Cursor.Current = Cursors.WaitCursor;
UpdateControl();
Cursor.Current = Cursors.Default;

Now to force the form to repaint when some other window is dragged
over it i use Application.DoEvents() that does its work but also
changes the wait cursor before 'UpdateControl()' function returns, if
user move mouse to that control.

Is there any workaround to achieve both repainting and keeping the
wait cursor at the same time?

Thanks
TF
 
J

Jay B. Harlow [MVP - Outlook]

TF,
Normally I "avoid" calling DoEvents in a loop to avoid this problem.

What I normally do is move the "takes some time" task to its own thread,
either by creating a System.Threading.Thread object or executing it
asynchronously via a Delegate.BeginInvoke.

Alternatively or in addition to the thread: Rather then setting
Cursor.Current you can set Form.Cursor (which is inherited from Control),
however you need to be certain to then change Form.Cursor back when you are
done.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top