Click here to Skip to main content
15,917,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,

I have a c# application that a user can access after logging in using his credentials, however I would like to lock the application after that a certain time x passes or the user can lock it by himself using a lock button. To unlock, the user has to enter his password in another winform and if correct he can unlock the app.

How can I do that?
Posted

1 solution

Hello

Simple way is using ShowDialog()

1. Use Timer Control in MainForm Look at here

2. After "n" seconds or after clicking a Button,(in MianForm):
C#
private void MyTimer_Tick(object sender, EventArgs e)
{
   MyTimer.Stop();
   AuthenticationForm.ShowDialog();
}


AuthenticationForm is a winFrom that you've created it for entering UserName and Password.

The application wont be accessible by user while the AuthenticationForm is opening.

3. If you want to pause another processes in the application, you can make it manually. (Use Event Handler)

4. If you use multiThreading then the solution may not work !

5. I prefer to set Enable of MainForm and other Forms to false instead of using ShowDialog(), then you need to store all opened form in a Collection for example List<Form>. You can overrid OnLoad(EventArgs e) method of Forms to store themselve into a static List. Form.OnLoad Method
It may be threadsafe but you must look at here first: Threading
 
Share this answer
 
v7
Comments
Mabchour 1989 8-Apr-12 18:46pm    
I got it, but the problem is in authenticating in the authenticationForm, i need to set it up so that the main form can be enabled again when i enter the right password.
Shahin Khorshidnia 9-Apr-12 6:31am    
After closing the AuthenticationForm, the MainForm will be enabled automatically.

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