Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i m working on window app... i m facing problem......actually i want hang my form if user is not working till 5 min .he got a message you have expired ..first u login u can activate......plz solve my problem




with regards
kuldeep vyas
developer in Real Expert cor pvt ltd.
Posted
Comments
Oshtri Deka 11-Oct-12 2:09am    
Let us see your code.

You'll need timer to measure idle time and some kind of tracking mechanism to keep track of user's interaction with form. If idle time elapses then you'll have to inform user with MessageBox etc.
In this case I would use System.Timers.Timer class.
C#
private void someTextBox_TextChanged(object sender, EvetArgs e)
{
    //do some work
    ResetIdleTimer();
}

private void someCheckBox_ChekChanged(object sender, EvetArgs e)
{
    //do some work
    ResetIdleTimer();
}

//.....
//etc. you got the picture
//.....

private void ResetIdleTimer()
{
   idleTimer.Stop();
   idleTimer.Start();
}


void idleTimer_Elapsed(object sender, ElapsedEventArgs e)
{
    MessageBox.Show("Whatever you want to say to user");
    //your logging off code  and closing code go here
    //this.Close();
}
 
Share this answer
 
Incorporate a System.Windows.Fomrs.Timer[^]. Set its Interval[^] property to five minutes. Subscribe a method to its Tick[^] event. In that method, disable your Form and show the "You've been logged out..." message.

Now you have to catch each and every possible user intaraction. With every user interaction, first Stop[^] the timer, then Start[^] it again. AFAIR that will cause the timer to wait for Interval again. If not, set the interval before calling Start.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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