自动关闭Windows应用程序 [英] Close windows application automatically

查看:76
本文介绍了自动关闭Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在c#.net中用一种形式开发了Windows应用程序.
我的要求是,当用户必须打开此应用程序并且在一段时间内不使用它"时(例如屏幕保护程序),应关闭此表单.
如果您知道该怎么做,请帮助我.

[edit]紧急情况已删除:这可能对您来说很紧急,但这只会使人烦恼,并且可能会减慢响应速度.
删除大写字母,拼写和讲语音的内容-OriginalGriff [/edit]

I have developed a windows application with one form in c#.net.
My requirement is this form should be closed when "user have to open this application and have not work on it some period of time" (like screen saver).
If you know how to do this please help me.

[edit]Urgency removed: It may be urgent for you, but it just annoys people and can slow a response.
Capitalisation, spelling, textspeak removed - OriginalGriff[/edit]

推荐答案

我不确定实施中的问题是什么.在窗体上保留一个计时器控件,并在给定时间段内对其进行配置.如果用户在给定时间内没有交互,请关闭表单/应用程序.

如果要根据计时器中的时间打开屏幕保护程序或新窗体,也可以这样做!
I am not sure whats the issue in implementation. Keep a timer control on the form and configure it for a given period. If user is not interacting for that given period then close the form/application.

If you want to open a screensaver or a new form, based on the time lapsed in the timer, you can do that too!


在窗体中设置计时器.将时间间隔设置为较短的时间:说三十秒.
设置一个DateTime.每当有活动"(无论您如何定义)时,都将DateTime重置为DateTime.Now.AddMinutes(30).
在计时器滴答事件"中,根据超时时间检查当前时间.
Set up a Timer in the form. Set it''s interval to a shortish period: say thirty seconds.
Set up a DateTime. Whenever there is "activity" (however you define that) reset the DateTime to DateTime.Now.AddMinutes(30).
In the Timer Tick Event check the current time against the timeout period.
DateTime closeDownAt;
private void Activity()
   {
   closeDownAt = DateTime.Now.AddMinutes(30);
   }

private activityTimer_Tick(object sender, EventArgs e)
   {
   if (DateTime.Now >= closeDownAt)
      {
      Close();
      }
   }





我使用了上面的代码,但没有用.是否需要更改计时器间隔.如果是,则如何更改.我是第一次使用计时器控件.请清楚解释."

您是否连接了Timer.Tick事件? :laugh:
如果不是,那么在您的Form Load事件代码中:





"I used the above code but its not working.Did i need to change the timer interval.If so,how to change.I am using timer control for the first time.Plz explain clearly."

Did you hook up the Timer.Tick event? :laugh:
If not then in your Form Load event code:

Activity();
activityTimer.Interval = 30000;   //30 seconds in milliseconds
activityTimer.Tick += new EventHandler(activityTimer_Tick);
activityTimer.Start();


给您大警告!您可以轻松地做到这一点,但是不要这么做!这是非常破坏性的应用程序行为,没有真正的用处.会吓死用户!

—SA
Big warning for you! You can easily do it, but don''t! This is very disruptive application behavior, not really useful. Will scare users to death!

—SA


这篇关于自动关闭Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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