Idle time

supermanzdead

Active member
Joined
Feb 23, 2006
Messages
31
Programming Experience
Beginner
I have the following code after my form loads to get idle time and show a message box after 30 seconds. It works but it eats up cpu time, how can i make this more efficient?? I am using GetLastInputInfo to get the idle time.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sec [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = clsIdle.IdleTimeInTicks / 1000
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] sec < 30
TextBox1.Text = sec [/SIZE][SIZE=2][COLOR=#008000]'seconds idle
[/COLOR][/SIZE][SIZE=2]sec = clsIdle.IdleTimeInTicks / 1000
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2]MessageBox.Show("you are idle")
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

 
My computer doesn't slow down

your code is working fine on my computer. But its true that in the task manager when the form runs, it displays CPU Usage as 100%. But still my computer responds normally while your code is executing (ie. it doesn't slow down). does your computer slow down a lot or its just the CPU Usage in the Task Manager, that is showing high values?

adrcam
 
I use both VS 2003 and VS 2005, only problem is the client I am programming for only has .Net 1.1 so I am stuck with 2003 :)

It isn't for a splash item, just to snag idle time on a workstation and then log it off if the time goes over x amount of seconds. Really simple :)
 
Back
Top