Solved

How To Logoff My App

Posted on 2008-06-12
10
155 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
ID: 21781173
* 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
ID: 21786202
Ok , How to follow the mouse and keyboard events within the whole application
0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21814625
Ok , How to follow the mouse and keyboard events within the whole application
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 21814907
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
ID: 21815391
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
 

Author Comment

by:Ahmadal_najjar2003
ID: 21815454
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 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 21815626
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
ID: 21816041
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 70

Expert Comment

by:Éric Moreau
ID: 21816118
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
ID: 31466784
Thank You a lot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

828 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