C# WPF应用程序不活动
我希望我的应用程序在空闲时执行某些操作。为此,我编写了这段代码,它只有在Dispatchermer间隔小于30秒,或者我的应用程序不是活动窗口时才能正常工作C# WPF应用程序不活动,c#,wpf,dispatchertimer,C#,Wpf,Dispatchertimer,我希望我的应用程序在空闲时执行某些操作。为此,我编写了这段代码,它只有在Dispatchermer间隔小于30秒,或者我的应用程序不是活动窗口时才能正常工作 static DispatcherTimer mIdle; public static void HandleWithTimeout(int timeout, Action handler) { InputManager.Current.PreProcessInput += d
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(); };
}
那么,在应用程序处于活动窗口的情况下,如何使其正常工作?为什么超时>=30秒时不能正常工作?我找到了答案:相反
InputManager.Current.PreProcessInput += delegate(object sender, PreProcessInputEventArgs args)
{
mIdle.IsEnabled = false;
mIdle.IsEnabled = true;
};
我写
InputManager.Current.PreNotifyInput += delegate
{
mIdle.IsEnabled = false;
mIdle.IsEnabled = true;
};
以下是预输入
、预输入
与其他InputManager EVNET之间的区别:
HandleWithTimeout
方法从应用程序调用一次Class@HenkHolterman“这没用,”亨克奥尔特曼说,“我找到了解决办法。我使用了错误的事件:相反,我使用了PreNotifyInput
事件,效果很好。不过,非常感谢你的帮助。