[英]WPF app inactivity
I want my app do something when it is idling.我希望我的应用程序在空闲时做一些事情。 For that I wrote this code, which works properly only when DispatcherTimer interval is less than 30 seconds, or my app is not active window.
为此,我编写了这段代码,它仅在 DispatcherTimer 间隔小于 30 秒或我的应用程序不是活动窗口时才能正常工作。
static DispatcherTimer mIdle;
public static void HandleWithTimeout(int timeout, Action handler)
{
InputManager.Current.PreProcessInput += delegate(object sender, PreProcessInputEventArgs args)
{
mIdle.IsEnabled = false;
mIdle.IsEnabled = true;
};
mIdle = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(timeout),
IsEnabled = true
};
mIdle.Tick += delegate { handler(); };
}
So how can I make this work in cases when app is active window, and why does this not work properly when timeout >=30 seconds?那么如何在应用程序处于活动窗口的情况下使其工作,为什么在超时> = 30 秒时无法正常工作?
I found the answer: instead我找到了答案:相反
InputManager.Current.PreProcessInput += delegate(object sender, PreProcessInputEventArgs args)
{
mIdle.IsEnabled = false;
mIdle.IsEnabled = true;
};
I wrote我写
InputManager.Current.PreNotifyInput += delegate
{
mIdle.IsEnabled = false;
mIdle.IsEnabled = true;
};
Here are the differences between PreProcessInput
, PreNotifyInput
and other InputManager evnets: https://msdn.microsoft.com/en-us/library/system.windows.input.inputmanager(v=vs.110).aspx以下是
PreProcessInput
、 PreNotifyInput
和其他 InputManager evnet 之间的区别: https ://msdn.microsoft.com/en-us/library/system.windows.input.inputmanager(v = vs.110).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.