Determine if the application had any action? Vb.net

Does anyone know how to detect recent activity in a Windows VB.net forms application?

We have a retail store in which users share computers on the floor, the application will be on each machine and requires a login before use. I am trying to find a way to automatically close the application, if it is idle, let's say 10 minutes.

I think I could do something similar with the current Windows session in the session - install gp, which logs the user after 10 minutes of inactivity, but if there is a simple, unsafe way to do this in vb.net, I would prefer to use this method

thanks

+4
source share
4 answers

When starting applications, create a handler for the Application.Idle event. Also create an object that is your 10 minute timer. The Appliation.Idle event occurs every time the event Appliation.Idle is empty. If you move the mouse, it triggers an event. If you press the key, it will result in an event. Note: you cannot use the Handles keyword with Application.Idle . Handles only works for locally decalized objects, not static objects.

 Public Sub MainForm_Load(sender As Object, e As EventArgs) Handles MainForm.Load AddHandler System.Windows.Forms.Application.Idle, AddressOf Application_Idle ' TODO: Create the 10-minute timer. End Sub Private Sub Application_Idle(sender As Object, e As EventArgs) ' TODO: Restart the 10-minute timer. End Sub ' This assumes your TenMinuteTimer object has an Expire event. Do what works for you instead. Private Sub TenMinuteTimer_Expire(sender As Object, e As EventArgs) Handles TenMinuteTimer.Expire ' TODO: Close the application safely. End Sub 

The only problem with this is that if the user runs an action that takes more than 10 minutes, he will raise Application.Idle after TenMinuteTimer.Expire . If you expect this to happen, be sure to disable TenMinuteTimer before executing the long code and enable it again.

+5
source

You can try to use the Application.Idle event; So:

 Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs) MessageBox.Show("You are in the Application.Idle event.") End Sub 
+1
source

I personally recommend the Windows implementation because you do not need to worry about all the different scenarios that might happen:

Close the application or leave it open?

What should I do if the user has an invitation (message box) displayed on the screen?

If you close the application down, how do you handle the current job?

If you do not close the application, how do you inform the user, and then if another user wants to log in, how do you gracefully roll back previous user information?

If another user wants to log in, how can you prevent them from seeing any confidential information that the previous user could leave on the screen?

However, if you want to continue this, then it is best to connect to standard message pipeline messages via IMessageFilter. Here 's a decent article on how to use it.

+1
source

You can periodically check the coordinates of the cursor and see if they have changed since the last check. After a certain number of checks without any changes, the application will then close. This is probably not the best method, but it is definitely an option.

0
source

Source: https://habr.com/ru/post/1380806/


All Articles