我目前正致力于从中注销用户一定量的闲置时间。我宣布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 –