Live Chat Icon For mobile
Live Chat Icon

I set the wait cursor using Cursor.Current = Cursors.WaitCursor;. Why does does it disappear before I want it to

Platform: WinForms| Category: Cursors

Setting the Current property changes the cursor and stops the processing of mouse events. Setting the cursor back to Cursors.Default restarts the mouse event processing and displays the proper cursor for each control. If a DoEvents is called before you reset the cursor back to the default, this will also start up the mouse event processing and you will lose the particular cursor you set. So, if your WaitCursor is disappearing, one explanation might be that DoEvents is getting called.

Here is some code that sets a WaitCursor.

	Cursor oldCursor = Cursor.Current;
	Cursor.Current = Cursors.WaitCursor;
	try 
	{
		// Do your processing that takes time...
		// eg. let’s wait for 2 seconds...
		DateTime dt = DateTime.Now.AddSeconds(2);
		while(dt > DateTime.Now)
		{ //do nothing	
		}
	}
	finally 
	{
		Cursor.Current = oldCursor;
	}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.