How do we do idle time processing in WPF application?

后端 未结 3 805
南方客
南方客 2020-12-17 21:50

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

相关标签:
3条回答
  • 2020-12-17 22:22

    It is the Dispatcher.Hooks.DispatcherInactive event.

    0 讨论(0)
  • 2020-12-17 22:35

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

    System.Windows.Interop.ComponentDispatcher.ThreadIdle += (_, __) =>
    {
        Debug.Print("Idle");
    };
    
    0 讨论(0)
  • 2020-12-17 22:36

    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);
    
    0 讨论(0)
提交回复
热议问题