I am working on a WPF application. The application uses Infragistics controls such as Ribbon Controls and XamDockManager. It has a File Menu wherein I have provided a Save menu item to save the items on the canvas to a file. On click of Save button, Save Dialog opens to provide the File name and file is saved at the defined location.
The saving process is quite time consuming and in order to show something to the user, I have used the WaitCursor.
I have used a class similar to the one mentioned(UiServices.ShowWaitCursor) in the below thread.
public void WriteToFile(string fileName)
This works fine, if we just save the things on the canvas into a file. However, if fails in the below scenario.
The application has a canvas where I display some UI elements. On double click of the UI element, we launch a Windows form in the Infragistic ContentPane.
We have a modeless dialog opened and perform File -> Save and provide a file name, the cursor stays indefinitely. It goes only once we click on the Canvas. The DispatcherTimer_Tick is fired only when we click on the Canvas which resets the cursor.
The DispatcherPriority is ApplicationIdle.
Another observation is, this happens only when we open the Save dialog through the File -> Save. It works fine if we open the Save dialog through Ctrl + S key combinations.
Is there a way I can debug the non firing of DispatcherTimer.Tick event or any other way to handle this?
I created a simple WPF application and it works fine in that.
///<summary>/// Interaction logic for MainWindow.xaml
///</summary>publicpartialclass MainWindow : Window
privatevoid button1_Click(object sender, RoutedEventArgs e)
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
form.Height = 200;
form.Width = 400;
form.TopMost = true;
privatevoid MenuItem_Click(object sender, RoutedEventArgs e)
string fileName = SaveFileDialog();
// Create SaveFileDialog
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
// Display SaveFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
string filename = string.Empty;
// Get the selected file name
if (result == true)
// Open document
filename = dlg.FileName;
///<summary>/// Sets the busy state on the application.
/// Displays a wait cursor for long running tasks.
///<summary>/// A value indicating whether the UI is currently busy
///<summary>/// Sets the state as busy.
///<summary>/// Sets the state to busy or not busy.
///</summary>///<paramname="busy">if set to <c>true</c> the application is now busy.</param>privatestaticvoid SetBusyState(bool busy)
if (busy != _isBusy &&
Application.Current != null &&
Application.Current.Dispatcher != null)
_isBusy = busy;
Mouse.OverrideCursor = busy ? Cursors.Wait : null;
new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, DispatcherTimer_Tick, Application.Current.Dispatcher);
///<summary>/// Handles the Tick event of the dispatcherTimer control.
///</summary>///<paramname="sender">The source of the event.</param>///<paramname="e">The <seecref="System.EventArgs"/> instance containing the event data.</param>privatestaticvoid DispatcherTimer_Tick(object sender, EventArgs e)
var dispatcherTimer = sender as DispatcherTimer;
if (dispatcherTimer != null)
I can't execute your code (I don't have those libraries you use), but can you use another priority?
I don't know... maybe you have an animation or similar that is never really letting the application become idle.
Note: Seeing your code, you don't need to use a DispatcherTimer. It is enough to do a Dispatcher.BeginInvoke to call your delegate. This will also guarantee that it will execute only once, as soon as all the messages (including the actual one) are processed. In fact, I think your problem is that you never started your timer.
Last Visit: 31-Dec-99 19:00 Last Update: 6-Feb-16 9:18