473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB.Net Application Idle timer

Hi, I built an event timer for my application, but I keep getting errors when i try to run it...bellow is my code, and then the error...If you have any sugestions please let me know...There error occurs durring the call to GetLastInputInfo():

Expand|Select|Wrap|Line Numbers
  1. Imports System.Windows.Forms
  2. Imports system.Runtime.InteropServices
  3.  
  4. Public Class IdleTimmer
  5.  
  6. #Region " InputInfo "
  7.     Private Declare Function GetLastInputInfo Lib "User32.dll" (ByRef lii As LASTINPUTINFO) As Boolean
  8.  
  9.     <StructLayout(LayoutKind.Sequential)> _
  10.     Public Structure LASTINPUTINFO
  11.         Public cbSize As UInteger
  12.         Public dwTime As UInteger
  13.     End Structure
  14. #End Region
  15.  
  16. #Region " Events "
  17.     Public Event UserIdleTimeExpired()
  18. #End Region
  19.  
  20. #Region " Variables "
  21.     Private WithEvents mTimmer As Timers.Timer
  22.     Private mTimeOut As UInteger
  23. #End Region
  24.  
  25. #Region " Events "
  26.     Private Sub mTimmer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles mTimmer.Elapsed
  27.         If GetIdleTimeInSeconds() >= mTimeOut Then
  28.             Me.Stop()
  29.             RaiseEvent UserIdleTimeExpired()
  30.         End If
  31.     End Sub
  32. #End Region
  33.  
  34. #Region " Functions "
  35.     Private Function GetIdleTimeInSeconds() As UInteger
  36.         Return (Environment.TickCount - GetLastInputTime()) / 1000
  37.     End Function
  38.  
  39.     Private Function GetLastInputTime() As UInteger
  40.         Dim lii As New LASTINPUTINFO
  41.         lii.cbSize = Marshal.SizeOf(lii)
  42.  
  43.         If GetLastInputInfo(lii) Then
  44.             Return Environment.TickCount - lii.dwTime
  45.         End If
  46.     End Function
  47. #End Region
  48.  
  49. #Region " Subs "
  50.     Public Sub Start(ByVal timeoutTime As UInteger)
  51.         If mTimmer Is Nothing Then mTimmer = New Timers.Timer
  52.  
  53.         mTimeOut = timeoutTime
  54.         mTimmer.AutoReset = True
  55.         mTimmer.Interval = 1000UI
  56.         mTimmer.Start()
  57.     End Sub
  58.  
  59.     Public Sub [Stop]()
  60.         If Not mTimmer Is Nothing Then mTimmer.Stop()
  61.     End Sub
  62. #End Region
  63.  
  64. End Class
  65.  
A first chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll
May 8 '07 #1
1 3985
maybe its the SizeOf which can't convert from Integer to UInteger when assigning cbSize. do like... CUInt(Marshal.SizeOf(lii))
May 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Josh | last post by:
Hi, I want to detect the keystroke entered by the user in my application. Actually the scenarion is, at first the user is entering some details to the windows form, later on he is idle for few...
19
by: Frank Rizzo | last post by:
I want to log the user out when there has been a period of inactivity in the application. The key here is inactivity of the application, not the system. I know that you can retrieve the...
3
by: Jeff Greenland | last post by:
Hello everyone, I am having problems with Timers in a web application. They just seem to stop running after 15 minutes or so. My web application is set up like this: When a user hits a...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
3
by: Peter Strøiman | last post by:
Hi. I have a web application that needs to run tasks at regular intervals. E.g. it must send out emails every night to people who subscribe to that service. I have come up with one solution,...
3
by: Law | last post by:
To all the VB master, i'm new baby in VB. I would like to get ur's advice on how to stop the application when user is not in use within 5 or 10mins? Hope to hear VB master soon. Tks, Law
1
by: Viet | last post by:
I don't know if this is the right forum for my question but here goes: I am converting a VB6 app to VB.NET and I would like to use Threads and Threadpools. This main app (1) executes two other sub...
5
by: hmy | last post by:
Hi, I need to lock my application if it has been idle for 15 minutes. This is a windows application in c#. I have put a timer in the main form and implemented the IMessageFilter interface. In the...
1
by: Visu | last post by:
Hi All! How to find the application idle time in VB.NET windows application? We can get the windows Idle time Private Declare Function GetLastInputInfo Lib "user32.dll" But i want the...
4
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
In VB I am doing an animation via Application.Idle. My idle routine is: Private Sub Form1_Idle(ByVal sender As System.Object, ByVal e As System.EventArgs) Draw() Application.RaiseIdle(e) End...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.