Baffa

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



Re: Windows Presentation Foundation (WPF) Changing the Cursor to Hourglass

Frances83

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.




Re: Windows Presentation Foundation (WPF) Changing the Cursor to Hourglass

Drew Marsh

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





Re: Windows Presentation Foundation (WPF) Changing the Cursor to Hourglass

Baffa

Hi,

Mouse.OverrideCursor = Cursors.Wait,

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

Thanks





Re: Windows Presentation Foundation (WPF) Changing the Cursor to Hourglass

Frances83

I would still implement Threading, though




Re: Windows Presentation Foundation (WPF) Changing the Cursor to Hourglass

vtcoder

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.