Application.DoEvent and wait cursor

  • Thread starter Thread starter TF
  • Start date Start date
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
 
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
 
Back
Top