1
我希望我的应用在空闲时做某些事情。为此,我编写了此代码,该代码仅在DispatcherTimer间隔小于30秒时正常工作,或者我的应用程序不是活动窗口。WPF应用闲置不动
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秒工作?
'HandleWithTimeout'方法被调用一次从应用程序类 – Aagha
@HenkHolterman它没有帮助。 – Aagha
@HenkHolterman我找到了解决方案。我使用的是错误的事件:改为'PreProcessInput'我使用了'PreNotifyInput'事件,它的效果很好。 不过非常感谢你的帮助。 – Aagha