我目前正致力於從中註銷用戶一定量的閒置時間。我宣佈Application.IdleApplication.Idle acting different
Private Sub Application_Idle(sender As Object, e As EventArgs)
Timer.Interval = My.Settings.LockOutTime
Timer.Start()
End Sub
然後,把它的形式加載事件
Private Sub ctlManagePw_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
AddHandler System.Windows.Forms.Application.Idle, AddressOf Application_Idle
End Sub
而且計時器
Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
Try
If My.Settings.TrayIcon = 1 Then
Me.ParentForm.Controls.Remove(Me)
control_acPasswords()
_Main.NotifyIcon.Visible = True
_Main.NotifyIcon.ShowBalloonTip(1, "WinVault", "You've been locked out due to innactivity", ToolTipIcon.Info)
End If
'Stop
Timer.Stop()
Timer.Enabled = False
'Flush memory
FlushMemory()
Catch ex As Exception
'Error is trapped. LOL
Dim err = ex.Message
End Try
End Sub
這樣做的問題是每當空閒事件結束我我仍然收到一封通知,表示我已經再次鎖定和/或應用程序已進入空閒事件。
control_acPasswords()
是註銷用戶控制
而且這裏是我釋放內存
Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal process As IntPtr, ByVal minimumWorkingSetSize As Integer, ByVal maximumWorkingSetSize As Integer) As Integer
Public Sub FlushMemory()
Try
GC.Collect()
GC.WaitForPendingFinalizers()
If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
Dim myProcesses As Process() = Process.GetProcessesByName(Application.ProductName)
Dim myProcess As Process
For Each myProcess In myProcesses
SetProcessWorkingSetSize(myProcess.Handle, -1, -1)
Next myProcess
End If
Catch ex As Exception
Dim err = ex.Message
End Try
End Sub
如果我把一個MsgBox(ex.Message)
上Timer_Tick事件例外,我不斷收到
Object reference not set to an instance of an object
我的預期結果是每當表單進入空閒事件時,它會得到間隔或從My.Settings.LockOutTime
這是一個分鐘的時間,並存儲爲60000
1 minute
或60 seconds
並啓動計時器的時間。現在在Timer_Tick上,然後logout
用戶如果間隔結束。
我是如何處理事件的?
你使用什麼類型的Timer?至少有3個我知道的框架稱爲'定時器'... –
定時器控件從工具箱。我剛把它命名爲Timer。 –
@Damien_The_Unbeliever –