如果用户不使用应用程序但仍无法打开,如何退出应用程序
我尝试过的事情:
尝试使倒数计时器回合不起作用 它不起作用,因为它开始计数是我想要的用户登录回合时开始计数,如果他不使用该应用程序并在20分钟后退出
private void Form1_Load(object sender, EventArgs e)
{
IdleTimer.Tick += new EventHandler(IdleTimer_Tick);
}
void Application_Idle(object sender, EventArgs e)
{
if (!IdleTimer.Enabled)
{
StartTimer();
}
}
private void StartTimer()
{
IdleTimer.Interval = (Int32)((60000.0D) * (0.2D));
IdleTimer.Enabled = true;
Debug.WriteLine("Timer Started : " + IdleTimer.Interval.ToString());
IdleTimer.Start();
}
void IdleTimer_Tick(object sender, EventArgs e)
{
IdleTimer.Enabled = false;
// Some cleanup code
// ....
// ....
Application.Exit(); // Or something like this
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
RestartTimer();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
RestartTimer();
}
private void StopTimer()
{
Debug.WriteLine("Stopping Timer.");
IdleTimer.Enabled = false;
IdleTimer.Stop();
}
private void RestartTimer()
{
StopTimer();
StartTimer();
}
此代码有什么问题?
我尝试
private void Dashboard_Load(object sender, EventArgs e)
{
Application.Idle += new EventHandler(Application_Idle);
this.KeyPreview = true;
}