If the aplication is inactive 2 or 3 minutes it must automatically logout.(may be using timer control)
The application is built using wpf and C# in (.net 3.5), in this the application should automatically logout if it is inactive for few minutes. i think one way is to use timer control and no ideas about other ways to do this task , if you know the concept and code for this using timercontrol or any other way, please guide me.
codeforme codeformePosted Mar 12, 2010, 12:47 AM
Sam HobbsPosted Mar 5, 2010, 3:48 PM
First, it is extrmely easy to determine when a .Net application becomes idle; the Application.Idle Event is fired when the application is idle. The documentation however is not clear whether it is for the thread or the process. Assuming you are not creating threads explicitly, that should not matter for you. The documentation also says that the Application.Idle Event must be detached when application is disposed, but I assume that is not necessary if you exit the process.
The problem is how to detect leaving idle. You can do that using a message filter, and if any keyboard message or any of the relevant mouse messages is processed, then the timer is stopped. The timer gets started again when the application idles again.
So that is the general concept. I have attached a sample. Note that all the relevant codes is in the Program.cs file.
Raaj KumarPosted Mar 5, 2010, 1:55 AM
You can do couple of things for this. I will tell you the concept . Since you want to monitor the state of the application you need have a secondary app which will monitor and trigger logout process. All the applications have a Process which in-turn has atleast has one Thread which is a MainThread. Now Process and Thread has states(Suspended,Start,Running) So you can monitor based on Process and Thread.
Process:
If you are going by process monitoring ,you have to create a secondary process and make that to monitor this process.
Below is the link for Multiprocess architecture in C#
http://www.codeproject.com/KB/DLL/MultiProcess.aspx
Thread:
Since your application is in Wpf you can employee this MultiThreading and make the child thread(Backgroundworker is a managed Thread that it will reduce your coding difficulties.) check for MainThread(UI Thread) State and do the logout process.
So I would suggest to go for MultiThreading which will be very easy to work with.
Regards,
raaj