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 8383263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:07:20+00:00 2026-06-09T17:07:20+00:00

I am trying to implement auto log off feature for my vb.net desktop application.

  • 0

I am trying to implement auto log off feature for my vb.net desktop application. Here is the code:

Private Sub AutoLogOffTimer(ByVal myUIContext As globals)

         If myUIContext.parameters.LogOutTime <> 0 Then
            myTimer = New System.Windows.Forms.Timer()
            myTimer.Enabled = False
            'myTimer.Dispose()
            myTimer.Interval = (myUIContext.parameters.LogOutTime * 60 * 1000) - 20000
            AddHandler myTimer.Tick, AddressOf logOutUser
            myTimer.Start()
            Application.AddMessageFilter(Me)
         ElseIf myUIContext.parameters.LogOutTime = 0 Then
            Application.RemoveMessageFilter(Me)
            RemoveHandler myTimer.Tick, AddressOf logOutUser
            myTimer.Stop()
            myTimer.Enabled = False
         End If
      End Sub

 Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements    IMessageFilter.PreFilterMessage

         ' Monitor message for keyboard and mouse messages
         Dim active As Boolean = m.Msg = &H100 OrElse m.Msg = &H101
         ' WM_KEYDOWN/U
         'active = active OrElse m.Msg = &HA0 ' OrElse m.Msg = &H200
         active = active OrElse m.Msg = &HA3 OrElse m.Msg = &H201 OrElse m.Msg = &H202 OrElse m.Msg = &H1 OrElse m.Msg = &H200 OrElse m.Msg = &H2 OrElse m.Msg = &H208 OrElse m.Msg = &H2A3 OrElse m.Msg = &H2A1
         ' WM_(NC)MOUSEMOVE
         active = active OrElse m.Msg = &H10 OrElse m.Msg = &H3 OrElse m.Msg = &H5
         ' WM_CLOSE, in case dialog closes
         If active Then
            myTimer.Enabled = False
            myTimer = New System.Windows.Forms.Timer()
            If _myUIContext.parameters.LogOutTime <> 0 Then
               myTimer.Interval = (_myUIContext.parameters.LogOutTime * 60 * 1000) - 20000
               Try
                  RemoveHandler myTimer.Tick, AddressOf logOutUser
               Catch ex As Exception
               End Try
               AddHandler myTimer.Tick, AddressOf logOutUser
               myTimer.Start()
               myTimer.Enabled = True
            ElseIf _myUIContext.parameters.LogOutTime = 0 Then
               myTimer = New System.Windows.Forms.Timer()
               myTimer.Stop()
            End If
         End If
         Return False
      End Function

 Private Sub logOutUser(ByVal sender As Object, ByVal e As EventArgs)

         If Not isLogoutWindowOpen Then
            If ComputeCpuUsage() < 1 Then
               LogoutWindow = New LogoutApp(20)
               AddHandler LogoutWindow.logOutCancel, AddressOf logOutCancel
               AddHandler LogoutWindow.logOutProceed, AddressOf logOutProceed

               LogoutWindow.MdiParent = Me
               LogoutWindow.Show()
               myTimer.Stop()

               isLogoutWindowOpen = True
            Else
               myTimer.Enabled = False
               myTimer.Start()
            End If

         End If

      End Sub

  Private Sub logOutCancel()

         myTimer = Nothing
         myTimer = New System.Windows.Forms.Timer()
         myTimer.Enabled = False
         myTimer.Stop()
         If _myUIContext.parameters.LogOutTime <> 0 Then
            myTimer.Interval = (_myUIContext.parameters.LogOutTime * 60 * 1000) - 20000
            myTimer.Start()
         End If
         myTimer.Enabled = True
         isLogoutWindowOpen = False
      End Sub

The problem is when i set the log out time to be lets say 1 minute, it works fine if and gives me the logout window after 1 minute if i do not do anything on my application. But after I cancel my logout window message and start working on my application the log out message box keeps coming up arbitrarily .First I thought my timers were not getting reset properly but myTimer.Enabled=False should have done the trick if no that myTimer.Start() should have definitely done the trick, but that that does not seem to work also. i have checked my pre-filter messages but still no luck.

Any help would be much appreciated.

Thanks.

  • 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-09T17:07:21+00:00Added an answer on June 9, 2026 at 5:07 pm

    OK I think I might have figured out your problem.

    Sometimes, Windows timers don’t care if they have been null referenced, and continue to fire their events without a parent. I think your problem lies in that in your logOutCancel code you are clearing the reference to the timer, but not first disabling it.

    Try a call to myTimer.Stop() before your line where you set myTimer = Nothing.

    Alternatively, why do you need to keep creating new Timers at all? Can’t you just stop then restart your original one?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a browser auto-complete feature for my application Login view. However
I am trying to implement auto complete feature in my rails application.I am able
I am trying to implement some code on my web page to auto-scroll after
I'm trying to implement auto-rotation in my application that is basically UINavigationController with lots
I was trying to implement small time delays in multithreading code using boost::this_thread::sleep. Here
I am trying to implement an auto logout functionality. If the application is not
I'm trying to implement an auto-save feature in a Knockout.js app. Is there a
i receive the following error when trying to implement auto-complete based on edismax type.
Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm trying to implement a facebook search in my system (auto suggest while typing).

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.