Ashish Ashu
Ashish Ashu

Reputation: 14677

How do we do idle time processing in WPF application?

Is there a way to do idle time processing in WPF application equivalent to OnIdle event in MFC?

Upvotes: 9

Views: 6300

Answers (3)

Jon Skeet
Jon Skeet

Reputation: 1503479

You can dispatch a task (using the Dispatcher in the normal way) with a DispatcherPriority of ApplicationIdle, which will only be executed when the application is idle. Sample code:

DispatcherPriority priority = DispatcherPriority.ApplicationIdle;    
Application.Current.Dispatcher.BeginInvoke(priority, action);

Upvotes: 11

noseratio
noseratio

Reputation: 61744

A late alternative answer (as a memo to myself):

System.Windows.Interop.ComponentDispatcher.ThreadIdle += (_, __) =>
{
    Debug.Print("Idle");
};

Upvotes: 1

Oleg Sych
Oleg Sych

Reputation: 6568

It is the Dispatcher.Hooks.DispatcherInactive event.

Upvotes: 6

Related Questions