Time out in .NET 2.0 windows application

Posted by Toashish80 under C# on 12/22/2010 | Points: 10 | Views : 5204 | Status : [Member] | Replies : 2
I have a Windows application in .NET 2.0 on c#. I am planning to implement Session time out throughout the application. The session time out interval has been configured using the app.config. In the main menu screen which comes after login, I have a timer which gets started as soon as the main menu loads. If the user does not selects any menu item then the interval would continue till the end and session expire message would be displayed. On click of OK the control would be redirected to Login form. If the user clicks on any meu item then the timer gets resetted to the default value and the screen opens. In this case when the timer value ends I am getting the session time out message but both the screen opened from the menu and the main menu screen are not getting closed.


Posted by: T.saravanan on: 12/22/2010 [Member] [MVP] Silver | Points: 25

Hi Toashish80,

Its small difficult one.I give my suggestions to you..its suitable means try this otherwise please don't consider....

1. Maintain one DateTime static object.
2. Add a Key and value in App.Config file for time interval (or) maintain a time interval in any static object.
3.When will user enter a login means using DateTime.Now to get current time and add the interval into that time.
4.To set that value into datetime static object.
5.In your all form load event (including main form) to check the following condition

if(dtSessinTime < DateTime.Now)
MessageBox.Show("Session Timedout!");
// If its Main form means just call the login form constructor
// Again add the Time interval...
dtSessinTime = DateTime.Now.AddMinutes("5");

6. If check a Session Time in all the events means just create a class and declare one boolean method for check the time it false means close the form.
That's my suggestion....
If its useful means try this way....

Cheers :)


Toashish80, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/6/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25


You can close do the forceful closing of the Menu form once the timer gets completed... with this.Close()


Toashish80, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response