Reputation: 43
I made small program which detects when is user idle. When is idle time greater then 10s program should open only a one messagebox. But in my case are run a multiple messageboxes. I know why its happen but I dont know how I can solve it. Thanks for every help.
If (inactiveTime Is Nothing) Then
ElseIf (inactiveTime.Value.TotalSeconds > 10000) Then
'Idle
Textbox1.text = "User is idle"
Msgbox("User is idle")
Else
'Active
Textbox1.text = "User is active"
End if
End if
Upvotes: 0
Views: 97
Reputation: 54532
Try using a class scoped Boolean variable as a flag to indicate that you are in the idle mode, reset it when user goes active, also make sure you reset the inactive time when the user goes active again.
i.e.
Dim idle As Boolean = False
then
If (inactiveTime Is Nothing) Then
ElseIf (inactiveTime.Value.TotalSeconds > 10000) Then
'Idle
If Not idle Then
Textbox1.text = "User is idle"
MsgBox("User is idle")
End If
idle = True
Else
'Active
idle = False
inactiveTime = 0
Textbox1.text = "User is active"
End If
Upvotes: 1