none
Changing the Cursor to Hourglass

    Question

  • Hi,

     

    I trying to change the cursor to the Hourglass, I have done this way:

     

    this.Cursor = Cursors.Wait;

    <.... process ....>

    this.Cursor = Cursors.Arrow;

     

    The problem is that when the process is executing the cursor does not change to the hourglasss, it was originally the Hand cursor and stays like that. But at the end it do turns to the Arrow.

     

    What must I do ?????

     

    Thanks in advance

    Thursday, May 03, 2007 1:03 PM

Answers

  • I would keep the UI and the process in different threads. Because your main thread gets busy with the process, it doesn't update the UI. Have a look at BackgroundWorkerThreads, they're very useful for these situations.
    Thursday, May 03, 2007 1:47 PM
  • Frances83's advice is right on. You need to do your long running process on a background thread otherwise you will tie up the UI thread and it will become unresponsive to the user. You can always spin up your own threads manually if you like, but have a look at the BackgroundWorker class which helps make this easier. Just be aware that when you need to interact with the UI from a worker thread you must marshal calls back to the dispatcher thread. That is done by using the Dispatcher property of the UI element you wish to "touch" and calling it's [Begin]Invoke method. Search the forums for tons of examples of how to do this.

     

    HTH,
    Drew

    Thursday, May 03, 2007 2:07 PM

All replies

  • I would keep the UI and the process in different threads. Because your main thread gets busy with the process, it doesn't update the UI. Have a look at BackgroundWorkerThreads, they're very useful for these situations.
    Thursday, May 03, 2007 1:47 PM
  • Frances83's advice is right on. You need to do your long running process on a background thread otherwise you will tie up the UI thread and it will become unresponsive to the user. You can always spin up your own threads manually if you like, but have a look at the BackgroundWorker class which helps make this easier. Just be aware that when you need to interact with the UI from a worker thread you must marshal calls back to the dispatcher thread. That is done by using the Dispatcher property of the UI element you wish to "touch" and calling it's [Begin]Invoke method. Search the forums for tons of examples of how to do this.

     

    HTH,
    Drew

    Thursday, May 03, 2007 2:07 PM
  • Hi,

     

    Mouse.OverrideCursor = Cursors.Wait,

     

    from the thread http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=676177&SiteID=1

     

    Thanks

     

    Friday, May 04, 2007 4:48 PM
  • I would still implement Threading, though
    Monday, May 07, 2007 6:02 AM
  • This solution works but I had a slight bug when I used it that basically wiped out all cursors set by individual controls. I was using something like this:

     

    Mouse.OverrideCursor = Cursors.Wait;

    ....processessing....

    Mouse.OverrideCursor = Cursors.Arrow;

     

    but the last statement overrides everything's cursor, so no individual control cursors remain (i.e., if you have buttons set to show hand, resize cursor for column header, etc). The correct use was to nullify the override like this:

     

    Mouse.OverrideCursor = Cursors.Wait;

    ....processessing....

    Mouse.OverrideCursor = null;

     

    Thought I'd pass this along in case someone else was scratching their head as to why their control cursors quit working.

    • Proposed as answer by sr pt Wednesday, January 14, 2009 6:49 PM
    Wednesday, August 08, 2007 7:52 PM