Click here to Skip to main content
13,095,218 members (81,537 online)

Silverlight / WPF

QuestionDispatcherTimer Tick event not fired Pin
Praveen Raghuvanshi17-Jan-13 4:54
memberPraveen Raghuvanshi17-Jan-13 4:54 

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.[^][^]

The usage is like this

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.


<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        <Menu Height="36" Name="menu1" Margin="12,0,439,197">
            <MenuItem Header="_File" Height="22" Name="menuitem1" Width="200" Margin="10, 10, 5, 5" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Chocolate">
                <MenuItem Header="Save..."  Click="MenuItem_Click"/>
        <Canvas Height="156" HorizontalAlignment="Left" Margin="81,77,0,0" Name="canvas1" VerticalAlignment="Top" Width="304" Background="#FF945050">
            <Button Canvas.Left="128" Canvas.Top="49" Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" />
            <TextBox Canvas.Left="48" Canvas.Top="128" Height="23" Name="textBox1" Width="120" />


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace WpfApplication1
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
		public MainWindow()
		private void 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;
		private void MenuItem_Click(object sender, RoutedEventArgs e)
			string fileName = SaveFileDialog();
		private string 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;
			return filename;
	/// <summary>
	/// Sets the busy state on the application.
	/// Displays a wait cursor for long running tasks.
	/// </summary>
	public static class UiServices
		/// <summary>
		/// A value indicating whether the UI is currently busy
		/// </summary>
		private static bool _isBusy;
		/// <summary>
		/// Sets the state as busy.
		/// </summary>
		public static void SetBusyState()
		/// <summary>
		/// Sets the state to busy or not busy.
		/// </summary>
		/// <param name="busy">if set to <c>true</c> the application is now busy.</param>
		private static void SetBusyState(bool busy)
			if (busy != _isBusy &&
				Application.Current != null &&
				Application.Current.Dispatcher != null)
				_isBusy = busy;
				Mouse.OverrideCursor = busy ? Cursors.Wait : null;
				if (_isBusy)
					new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, DispatcherTimer_Tick, Application.Current.Dispatcher);
		/// <summary>
		/// Handles the Tick event of the dispatcherTimer control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private static void DispatcherTimer_Tick(object sender, EventArgs e)
			var dispatcherTimer = sender as DispatcherTimer;
			if (dispatcherTimer != null)

Thanks in advance!
AnswerRe: DispatcherTimer Tick event not fired Pin
Paulo Zemek23-Jan-13 6:28
memberPaulo Zemek23-Jan-13 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 18 Aug 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid