How to show waitcursor?

Topics: Prism v2 - WPF 3.5
Mar 11, 2009 at 5:03 PM
I'm building a WPF desktop app using Prism v2 that communicates with a set of services via WCF.  I'm binding buttons in my views to delegatecommands.  Command execute methods in the presentationmodel classes call services which can take a few moments to return.  I don't see how to set the mouse cursor to an hourglass for the duration of the process, given the loose binding.  There's no mention of mouse cursors in the CAL docs that I can find, nor any posts on the net, and the StockTrader doesn't seem to provide this common feature. 
Thanks for any help you can provide,
 -Will 
Mar 11, 2009 at 6:34 PM
Hi Will!

Beleive it or not we've just put together a solution for our own project, but for Silverlight.

Here is how we had in our project which is a "prerequisite":
- All proxies are instantiated by a factory class, so it's responsible for creating and adding the WCF related stuff to it.
- We've defined 3 events: ShowHourglassEvent, HideHourglassEvent, UpdateProgressStatusEvent

Our solution is:
We've implemented a class which derives from IClientMessageInspector. It has an IsHandlingHourglass property.
In it's BeforeSendRequest method if IsHandlingHourglass is true we're publishing a ShowHourglassEvent, in it's AfterReceiveReply method we're publishing the HideHourglassEvent.
There is a "dedicated" module, which has the View, Controller, ViewModel classes. It's subscribing to the events above.

The purpose of the IsHandlingHourglass property is let the caller decide about automatic or manual show/hide. If you've to execute a series of WCF calls then you'd like to avoid flickering AND you need to update the status text between calls. So that's where the 3rd event comes in, it's goal is obvious: display a progress update.

Hope this helps or at lest gives some ideas.

- Attila
May 22, 2009 at 6:51 PM

attilah, sorry for the long delay.  I didn't understand enough from your original reply to implement a solution.  Other stuff came up and I put the whole thing on the back burner.  But I'm now down to 'the short strokes' and need to finally to get this solved. In the users eyes, it is a glaring deficiency that I don't display a waitcursor

It's still not clear to me where the cursor is actually getting set, in other words, in what class does the line "Mouse.OverrideCursor = Cursors.Wait;" reside?  Having the IClientMessageInspector publishing events to the eventaggregator implies to me that code that is calling a service would need to raise a Windows event rather than a CompositePresentationEvent.  And if that were the case, who subscribes to the CompositePresentationEvent that is published from the class that derives from IClientMessageInspector?

From what I can tell, I need a class that has both a reference to the eventaggregator and direct access to the Window.  Our Shell.xaml.cs could do it if I could get the eventaggregator injected into it, but I don't see how the bootstrapper could accomplish that.

Prism (desktop) has got to have some means to support controlling the mouse cursor.

Thanks for any more clues you can provide.

-Will

 

May 22, 2009 at 7:42 PM
Edited May 22, 2009 at 7:49 PM

Hi. 

I implemented something similar by creating a class that implements IDisposable. As an example:

/// <summary>

/// USAGE:

/// using (OverrideCursor cursor = new OverrideCursor(Cursors.Wait))

/// {

///     Do work...

/// }

/// </summary>

public class OverrideCursor:IDisposable

{

        public OverrideCursor(Cursor changeToCursor)

        {

            Mouse.OverrideCursor = changeToCursor;

        }

        #region IDisposable Members

        public void Dispose()

        {

            Mouse.OverrideCursor = null;

        }

        #endregion

}

- Best,


 

Nov 6, 2009 at 11:30 AM

I am also looking into how to set the cursor.    Fo rme I want to have the wait cursor application wide so I have gone the same path as you did but without success

I setup an ApplicationWaitCursorEvent in the Infratructure project.   In the Shell Presenter I subscribe to this event.

 I have an abstract base presenter class used for each module in my app and I have a method in this base class that publishes a true or false parameter with the ApplicationWaitCursorEvent event.

The problem I am having is that the Event callback method in the ShellPresenter does not fire.

 

Is this a valid approach to this probem ?

Are there any restrictions using the event aggrigator in the shell presenter? 

Nov 6, 2009 at 11:30 AM
Edited Nov 6, 2009 at 11:30 AM

I am also looking into how to set the cursor.    Fo rme I want to have the wait cursor application wide so I have gone the same path as you did but without success

I setup an ApplicationWaitCursorEvent in the Infratructure project.   In the Shell Presenter I subscribe to this event.

 I have an abstract base presenter class used for each module in my app and I have a method in this base class that publishes a true or false parameter with the ApplicationWaitCursorEvent event.

The problem I am having is that the Event callback method in the ShellPresenter does not fire.

 

Is this a valid approach to this probem ?

Are there any restrictions using the event aggrigator in the shell presenter? 

Did you eventually get your wait cursor to work?

Nov 6, 2009 at 12:15 PM

Please ignore my post I got it working.

I was not using the same instance of the EventAggrigator service.