Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to design a form in which,if i am not working for 10 min on that form. then it will automatically closed or if i am working with that form continuously for whichever , it will not closed. in c#
Posted

Hi
you can use this technique

1) MouseMove - event used to check whether the screen is active or not..
2) Timer - used to check the interval of 10 mins

rest you can understand from the below code..


C#
private void Form1_Load(object sender, EventArgs e)
       {
           t.Tick += new EventHandler(t_Tick);
           t.Start();

       }

       Timer t = new Timer() { Interval = 5000 }; //600000 for 10 minutes , 5000 for 5 seconds (testing)
       private void Form1_MouseMove(object sender, MouseEventArgs e)
       {
           t.Stop();
           this.Text = "active" + DateTime.Now.ToString(); //  testing purpose
           t.Start();

       }

       void t_Tick(object sender, EventArgs e)
       {
           MessageBox.Show("Application will exit now ");
           Application.Exit();
       }


use this widget for time calculation.
Minutes to Milliseconds[^]
 
Share this answer
 
v2
HI...

You have to set Session for this requirement.

Just add code in Global.asax file.

C#
protected void Session_End(object sender, EventArgs e)
{
  Response.Redirect("~/PathToYourRedirectPage.aspx");
}


And this code in Web.config file.
<sessionstate timeout="10" cookieless="false" mode="InProc" />


you can change timeout as per your requirement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900