Solved

How To Logoff My App

Posted on 2008-06-12
10
153 Views
Last Modified: 2010-04-30
for Windows Application with vb 2005 , if the user doesn't do any thing with a while say 5 minuets , I want the system to automatically log off.  
0
Comment
Question by:Ahmadal_najjar2003
  • 6
  • 3
10 Comments
 
LVL 10

Expert Comment

by:cool12399
Comment Utility
* Have 1 global integer variable
* Have a timer that increments this global variable each second by 1
* if the value is higher than 5*60 (ie 300 = 5 minutes), then close application
* For any mouse/keyboard event that is triggered in the application, reset the global variable to 0
0
 

Author Comment

by:Ahmadal_najjar2003
Comment Utility
Ok , How to follow the mouse and keyboard events within the whole application
0
 

Author Comment

by:Ahmadal_najjar2003
Comment Utility
Ok , How to follow the mouse and keyboard events within the whole application
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
A long time ago (in an old VB6 application) I was having an invisible form with a timer which every half minute was checking for the active form, the active control on that form and the value of that control when possible. If none of those values were modified for 5 minutes (I was checking every 30 seconds) then I was leaving the application. Maybe you can do something like this.
0
 

Author Comment

by:Ahmadal_najjar2003
Comment Utility
It is really a nice Idea , but in some cases give this message
"Object reference not set to an instance of an object"

While My Code Like this

If MyMousePosition = Control.MousePosition And _
           MyActiveForm = ActiveForm.Name And MyActiveControl = ActiveForm.ActiveControl.Name Then

do you have any Idea, Why.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Ahmadal_najjar2003
Comment Utility
After I watch the Error , it belongs to ActiveForm.name , I feel this happen while I am closing the active form.

Any Suggest
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
Comment Utility
You can trap it something like this:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static sstrPreviousForm As String = String.Empty
        Static sstrPreviousControl As String = String.Empty
        Static sdtmLastAction As DateTime

        Dim strCurrentForm As String
        Dim strCurrentControl As String
        Try
            strCurrentForm = ActiveForm.Name
        Catch ex As Exception
            strCurrentForm = String.Empty
        End Try

        Try
            strCurrentControl = ActiveForm.ActiveControl.Name
        Catch ex As Exception
            strCurrentControl = String.Empty
        End Try

        If (strCurrentForm <> sstrPreviousForm) OrElse (strCurrentControl <> sstrPreviousControl) Then
            sstrPreviousForm = strCurrentForm
            sstrPreviousControl = strCurrentControl
            sdtmLastAction = Date.Now
            Label1.Text = sstrPreviousForm
            Label2.Text = sstrPreviousControl
        End If
        Label3.Text = DateDiff(DateInterval.Minute, sdtmLastAction, Date.Now).ToString ' Date.Now.ToLongTimeString

        If DateDiff(DateInterval.Minute, sdtmLastAction, Date.Now) > 5 Then Application.Exit()
    End Sub
0
 

Author Comment

by:Ahmadal_najjar2003
Comment Utility
Thats Very Nice .

Thank You Very Much. But I need from you one thing if you can. You Use static inside the timer
is this mean just for the first time when fired just assign string.empty value . then after that will keep the value which which assign later. If you can help me for the lifetime and visibilty of this .

0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
Static variables have the lifetime of the class (form) in which it is found but they are only visible from within the method.
0
 

Author Closing Comment

by:Ahmadal_najjar2003
Comment Utility
Thank You a lot
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now