473,394 Members | 2,063 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,394 software developers and data experts.

time-out form

I need to implement a time-out form under .net(vb.net). So far I have been
able to creat a child thread which checks to see when the application
exceeds a set idle time. .. My problem is the fact the once I call a
callback function which invokes the time-out form , there is no way for me
to exit the child thread. The time-out form has 2 options: to restart the
program or to go back to the last viewed page.My implementation of the child
thread looks something like this .

Public Class IdleTimer

Implements System.IDisposable

Public Structure LastInputInfo

Public cbsize As Int32

Public dwtime As Int32

End Structure

Public Delegate Sub IdleTimeCallback()

Public callback As IdleTimeCallback

'Public callback As WaitOrTimerCallback

Public WithEvents frm As New Form

Public Shared ThreadCount As Integer = 0

Public MaxIdleTime As Integer = 30000

Private _idleTimerThread As Thread

Private _parentThread As Thread

'Public ReadOnly Property IdleTimerRunning() As Boolean

' Get

' Return Me._idleTimerRunning

' End Get

'End Property

Declare Auto Function GetLastInputInfo Lib "user32.dll" (ByRef value As
LastInputInfo) As LastInputInfo

Sub New(ByVal mit As Integer, ByRef cb As IdleTimeCallback)

Me.MaxIdleTime = mit

Me.callback = cb

Me.ThreadCount += 1

Me._parentThread = Thread.CurrentThread

End Sub

Public Sub StartIdleTimer()

'If (Me._idleTimerRunning = True) Then

' Throw New Exception("Timer is already running")

'End If

'Me._idleTimerRunning = True

Me._idleTimerThread = New Thread(New ThreadStart(AddressOf
IdleTimerThreadMain))

Me._idleTimerThread.Name = "IdleTimerThread[" & Me.ThreadCount & "]"

Me._idleTimerThread.Start()

'Me._idleTimerThread.Join()

End Sub

Public Sub StopIdleTimer()

' If (Me._idleTimerRunning = False) Then

' Throw New Exception("Timer is not running")

' Exit Sub

' End If

Me._idleTimerThread.Abort()

'Me._idleTimerRunning = False

End Sub

Private Sub IdleTimerThreadMain()

Dim lii As LastInputInfo

lii.cbsize = System.Runtime.InteropServices.Marshal.SizeOf(lii)

Dim currentTicks As Integer

Dim lastInputTicks As Integer

Dim idleTicks As Integer

While (True)

Me.GetLastInputInfo(lii)

currentTicks = System.Environment.TickCount

lastInputTicks = lii.dwtime

idleTicks = currentTicks - lastInputTicks

Dim debug As StringBuilder = New StringBuilder

debug.AppendFormat("Current tick = {0}, ", currentTicks)

debug.AppendFormat("Last input tick = {0}, ", lastInputTicks)

debug.AppendFormat("Differenc = {0}, ", idleTicks)

System.Diagnostics.Debug.WriteLine(debug.ToString)

If (idleTicks >= Me.MaxIdleTime) Then

Exit While

End If

System.Threading.Thread.Sleep(1000)

End While

Me.callback()

Application.Run()

End Sub

Public Sub Dispose() Implements System.IDisposable.Dispose

System.Diagnostics.Debug.WriteLine("Timer diposed")

End Sub

Protected Overrides Sub Finalize()

System.Diagnostics.Debug.WriteLine("Timer finalize")

End Sub

End Class
Please help

Dayne
Jul 21 '05 #1
1 1297
Dayne,

Does this sample I once made maybe help you in this.
http://groups.google.com/groups?selm...TNGP10.phx.gbl

I hope this helps?

Cor

"Dayne" <d_**********@hotmail.com>
I need to implement a time-out form under .net(vb.net). So far I have been
able to creat a child thread which checks to see when the application
exceeds a set idle time. .. My problem is the fact the once I call a
callback function which invokes the time-out form , there is no way for me
to exit the child thread. The time-out form has 2 options: to restart the
program or to go back to the last viewed page.My implementation of the
child
thread looks something like this .

Public Class IdleTimer

Implements System.IDisposable

Public Structure LastInputInfo

Public cbsize As Int32

Public dwtime As Int32

End Structure

Public Delegate Sub IdleTimeCallback()

Public callback As IdleTimeCallback

'Public callback As WaitOrTimerCallback

Public WithEvents frm As New Form

Public Shared ThreadCount As Integer = 0

Public MaxIdleTime As Integer = 30000

Private _idleTimerThread As Thread

Private _parentThread As Thread

'Public ReadOnly Property IdleTimerRunning() As Boolean

' Get

' Return Me._idleTimerRunning

' End Get

'End Property

Declare Auto Function GetLastInputInfo Lib "user32.dll" (ByRef value As
LastInputInfo) As LastInputInfo

Sub New(ByVal mit As Integer, ByRef cb As IdleTimeCallback)

Me.MaxIdleTime = mit

Me.callback = cb

Me.ThreadCount += 1

Me._parentThread = Thread.CurrentThread

End Sub

Public Sub StartIdleTimer()

'If (Me._idleTimerRunning = True) Then

' Throw New Exception("Timer is already running")

'End If

'Me._idleTimerRunning = True

Me._idleTimerThread = New Thread(New ThreadStart(AddressOf
IdleTimerThreadMain))

Me._idleTimerThread.Name = "IdleTimerThread[" & Me.ThreadCount & "]"

Me._idleTimerThread.Start()

'Me._idleTimerThread.Join()

End Sub

Public Sub StopIdleTimer()

' If (Me._idleTimerRunning = False) Then

' Throw New Exception("Timer is not running")

' Exit Sub

' End If

Me._idleTimerThread.Abort()

'Me._idleTimerRunning = False

End Sub

Private Sub IdleTimerThreadMain()

Dim lii As LastInputInfo

lii.cbsize = System.Runtime.InteropServices.Marshal.SizeOf(lii)

Dim currentTicks As Integer

Dim lastInputTicks As Integer

Dim idleTicks As Integer

While (True)

Me.GetLastInputInfo(lii)

currentTicks = System.Environment.TickCount

lastInputTicks = lii.dwtime

idleTicks = currentTicks - lastInputTicks

Dim debug As StringBuilder = New StringBuilder

debug.AppendFormat("Current tick = {0}, ", currentTicks)

debug.AppendFormat("Last input tick = {0}, ", lastInputTicks)

debug.AppendFormat("Differenc = {0}, ", idleTicks)

System.Diagnostics.Debug.WriteLine(debug.ToString)

If (idleTicks >= Me.MaxIdleTime) Then

Exit While

End If

System.Threading.Thread.Sleep(1000)

End While

Me.callback()

Application.Run()

End Sub

Public Sub Dispose() Implements System.IDisposable.Dispose

System.Diagnostics.Debug.WriteLine("Timer diposed")

End Sub

Protected Overrides Sub Finalize()

System.Diagnostics.Debug.WriteLine("Timer finalize")

End Sub

End Class
Please help

Dayne

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bart Nessux | last post by:
am I doing this wrong: print (time.time() / 60) / 60 #time.time has been running for many hours if time.time() was (21600/60) then that would equal 360/60 which would be 6, but I'm not getting...
6
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone...
4
by: Andrew Poulos | last post by:
How do I convert a length of time, measured in seconds, into a "point in time" type time interval or what's represented as: time (second,10,2) The format is: PS]] where: y: The number of...
8
by: peterbe | last post by:
What's the difference between time.clock() and time.time() (and please don't say clock() is the CPU clock and time() is the actual time because that doesn't help me at all :) I'm trying to...
3
by: Szabolcs Nagy | last post by:
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i...
6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
5
by: Erich Schreiber | last post by:
In the Python Library Reference the explanation of the time.sleep() function reads amongst others: > The actual suspension time may be less than that requested because > any caught signal will...
1
by: heirou | last post by:
I'm a novice in this subject....I've made a database that requires a time conversion. For example, if local time is 1200, determine the time in Korea. I use two fields: a date field, and a time...
3
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And...
2
by: Roseanne | last post by:
We are experiencing very slow response time in our web app. We run IIS 6 - windows 2003. I ran iisstate. Here's what I got. Any ideas?? Opened log file 'F:\iisstate\output\IISState-812.log'...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.