Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would the hourglass (WaitCursor) stop spinning?

I've got code in a button click like so:

try
{
    Cursor = Cursors.WaitCursor;
    GenerateReports();
}
finally
{
    Cursor = Cursors.Default;
    GC.Collect();
    GenPacketBtn.Enabled = true;
}

Nowhere else but in the finally block is the cursor set back to default, yet it does "get tired" and revert to its default state for some reason. Why would this be, and how can I assure that it will not stop "waiting" until the big daddy of all the processes (GenerateReports()) has completed?

like image 426
B. Clay Shannon-B. Crow Raven Avatar asked Oct 19 '22 20:10

B. Clay Shannon-B. Crow Raven


1 Answers

Use instead Control.UseWaitCursor = true, this does not time out.

If an expensive operation is being executed then Windows will take over and it will change the Cursor.WaitCursor to whatever it deems necessary. So with Cursor.WaitCursor it will either due to a timeout (but not fully sure about this) or because of Windows simply claiming ownership of the cursor without regards to its previous state. We also had a similar situation with where the Cursor did not behave as expected when performing an expensive task that involved called 3rd party PDF converters but we did not investigate more on the nature of the issue as it was not a priority.

After a bit of reading, it turned out setting the Hourglass cursor is a bit more complicated than it seems:

.net WaitCursor: how hard can it be to show an hourglass?

Also as a side note: you should use Cursor.Current = Cursors.WaitCursor as this forces the cursor to change to busy immediately , more details at : https://stackoverflow.com/a/302865/1463733

like image 144
Ahmad Avatar answered Nov 15 '22 05:11

Ahmad