Session out functionality in window application [duplicate]
Possible Duplicate:
Detecting idle users in Winforms
I am working with a desktop application and i want to lock the application if the it is idle from a specific time, if there is any event fired the开发者_如何学Pythonn the expiry time should be reset. When the application locked then user have to again enter username and password if he want to login again in the application.
Right now I am working with timer control to handle this functionality but i don't know the right place to write the code for reset the expiry time.
Pleas tell me how i can do that job...
You could have a timer control that when fires hides all the forms, and produces a login box.
That should point you in the right direction - I won't just give you the code.
Here is a very good example. Detecting Application Idleness
You could use Application.Idle Event also, but you will have to implement your own locking logic. In fact you can use that even for reset/start your ideal timer.
EDIT 1
Another good article and example.
EDIT 2
This function retrieves the time in seconds since last user input. However this is not specifically for your application but for windows. Look at here for more details. And here is a similar thread.
static int GetLastInputTime()
{
int idleTime = 0;
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = Marshal.SizeOf( lastInputInfo );
lastInputInfo.dwTime = 0;
int envTicks = Environment.TickCount;
if ( GetLastInputInfo( ref lastInputInfo ) )
{
int lastInputTick = lastInputInfo.dwTime;
idleTime = envTicks - lastInputTick;
}
return (( idleTime > 0 ) ? ( idleTime / 1000 ) : 0);
}
精彩评论