检测win表空闲时间进行注销 [英] Detecting win form idle time for doing logout

查看:65
本文介绍了检测win表空闲时间进行注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这是这个问题的正确位置。

我需要在[300]秒没有用户活动后注销Win Form应用程序。我看到了很多解决方案,包括检测空闲状态,最后一个Activity以及这个非常复杂的组件 - 检测Win Form空闲时间注销以及检测应用程序闲置

在第二篇文章中, Sara Kulu 的评论显示了一种非常简单的方法来做同样的事情。这很简单,让我担心。我在MDI应用程序中测试了它。当表单上有/不是 活动并且忽略它的活动时,它很有用。这太简单了。任何人都可以提出任何问题吗?



I hope this is the right place for this question.
I need to logout a Win Form Application after there is no user activity for [300] seconds. I saw lots of solutions, including detecting Idle State, last Activity and this really sophisticated component here - Detecting Win Form Idle Time for doing logout as well as Detecting Application Idleness
In the second article though was a comment by Sara Kulu that showed a very very simple way to do the same thing. It's so simple that is concerns me. I tested it in a MDI application. It works great when there is/is not activity on the Form and ignores activity off of it. It's just too easy. Can anyone suggest any problems with it?

DateTime dtLastIdleTime = DateTime.Now;
protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);
    dtLastIdleTime = DateTime.Now;
}




private void timer1_Tick(object sender, EventArgs e)
{
    appendToFile("\r\nTimer Says:" + DateTime.Now.ToLocalTime() + "..." + dtLastIdleTime.ToLocalTime() + "...");
}





我的尝试:



我试过这个并且效果非常好。如果有人能告诉我它的问题,我将不得不尝试其他更复杂的方法之一...那是怎么回事?



What I have tried:

I tried this and it worked wonderfully. If anyone can tell me a problem with it, I'll have to try one of the other more complicated methods... How's that?

推荐答案

WndProc不只是当用户执行某些操作时调用 - 只要Windows中出现可能影响应用程序的任何内容,就会调用它。例如,如果您移动另一个应用程序以显示您的应用程序 - 即使是部分 - 那么将调用WndProc重新绘制您的显示。哎呀,如果鼠标穿过应用程序,WndProc将被调用!



这不是一个好用户使用我的应用程序指标!您需要监控实际活动,而不仅仅是窗口中发生的事情。
WndProc is not just called when your user does something - it's called whenever anything happens in Windows that might affect your application. For example, if you move a different app so your app's is shown - even in part - then WndProc will be called to repaint your display. Heck, if the mouse crosses the application WndProc will be called!

It isn't a good "the user is using my app" indicator! You need to monitor for actual activity, not just "something happened in windows".


这篇关于检测win表空闲时间进行注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆