私は現在、一定の非アクティブ時間でユーザーをログアウトする from に取り組んでいます。Application.Idle を宣言しました
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
これに関する問題は、Idle イベントが終了するたびに、再びロックアウトされた、および/またはアプリケーションが Idle イベントに入ったという通知をまだ受け取っていることです。
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
Timer_TickMsgBox(ex.Message)
イベント例外を設定すると、取得し続けます
Object reference not set to an instance of an object
私の予想される結果は、フォームが Idle イベントに入るときはいつでも、My.Settings.LockOutTime
分の値である間隔または時間を取得し、またはとして保存し60000
、1 minute
タイマー60 seconds
を開始することです。Timer_Tick でlogout
、間隔が終了した場合はユーザー。
イベントの処理方法に何か問題がありますか?