WinForm实现程序一段时间不运行自动关闭的方法
本文实例讲述了WinForm实现程序一段时间不运行自动关闭的方法。分享给大家供大家参考。具体实现方法如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Net;
usingSystem.IO;
usingSystem.Security.Cryptography.X509Certificates;
usingSystem.Net.Security;
namespaceDemoDataGridView
{
publicpartialclassForm3:Form,IMessageFilter
{
privateintm_WaitMinute=0;
System.Windows.Forms.TimerMyTimer;
publicForm3()
{
InitializeComponent();
MyTimer=newTimer();
MyTimer.Interval=1000;
MyTimer.Tick+=newEventHandler(MyTimer_Tick);
Application.Idle+=newEventHandler(Application_Idle);
}
voidMyTimer_Tick(objectsender,EventArgse)
{
if(m_WaitMinute<60)
{
MyTimer.Enabled=true;
MyTimer.Interval=10000;//10秒
m_WaitMinute+=1;
//this.Opacity=1.0-Convert.ToDouble(m_WaitMinute/60.0);
}
else
{
MyTimer.Enabled=false;
}
}
voidApplication_Idle(objectsender,EventArgse)
{
if(m_WaitMinute==0)
{
System.IO.File.WriteAllText("D:\\1.txt",DateTime.Now.ToString());
MyTimer.Start();
}
else
{
if(m_WaitMinute>=6)
{
System.IO.File.WriteAllText("D:\\2.txt",DateTime.Now.ToString());
this.Close();
}
}
}
publicboolPreFilterMessage(refMessagem)
{
if(m_WaitMinute!=0)
{
m_WaitMinute=0;
MyTimer.Enabled=false;
returntrue;
}
returnfalse;
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下