简体   繁体   中英

How do we do idle time processing in WPF application?

有没有办法在 WPF 应用程序中进行空闲时间处理,相当于 MFC 中的 OnIdle 事件?

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);

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM