Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8565465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:26:01+00:00 2026-06-11T17:26:01+00:00

I’m currently working on a from that will logout the user in a certain

  • 0

I’m currently working on a from that will logout the user in a certain amount of inactivity time. I declared Application.Idle

Private Sub Application_Idle(sender As Object, e As EventArgs)
    Timer.Interval = My.Settings.LockOutTime
    Timer.Start()
End Sub

Then, call it on form load event

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

And on the timer

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

The problem with this is whenever an Idle event is over I’m still getting a notification that I’ve been lockout again and/or the application has entered an Idle event.

control_acPasswords() is the logout user control

And here is where I free up memory

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

If I put a MsgBox(ex.Message)on Timer_Tick event Exception, I keep getting

Object reference not set to an instance of an object

My expected result is whenever the form enters the Idle event, it will get the interval or the time from My.Settings.LockOutTime which is a minute value and stored as 60000 for 1 minute or 60 seconds and start the timer. Now on Timer_Tick then logout the user if the interval is over.

Is there something wrong how I handle events?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:26:02+00:00Added an answer on June 11, 2026 at 5:26 pm

    The Application.Idle event fires multiple times. Every time Winforms retrieved all messages from the message queue and emptied it. Problem is, the second and subsequent times it fires, you are starting a timer that was already started. That has no effect, you have to reset it so it starts ticking again for the programmed interval. Easy to do:

    Private Sub Application_Idle(sender As Object, e As EventArgs)
        Timer.Interval = My.Settings.LockOutTime
        Timer.Stop()
        Timer.Start()
    End Sub
    

    Next problem, possibly the reason for the exception, is that you explicitly have to unsubscribe the event when your form closes. It is not automatic, Application.Idle is a static event. Use the FormClosed event:

    Protected Overrides Sub OnFormClosed(ByVal e As System.Windows.Forms.FormClosedEventArgs)
        Timer.Stop()
        RemoveHandler Application.Idle, AddressOf Application_Idle
        MyBase.OnFormClosed(e)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.