|
-
Jan 17th, 2001, 08:56 AM
#1
Thread Starter
Lively Member
If Timer.Enabled Then: Windows.Crash
This question is directed to anyone that has had the same problem as me but found a solution:
When I go out of my room I often leave the internet running, with MSN Messenger on. I made a program in VB that automatically replies to anyone that IMs me when I'm out. However, this uses a timer that ticks every 10 seconds, and it isn't uncommon to find that the program has crashed. I've experienced this problem before with the VB timer control when I made a motion sensor program for my webcam. Is there a way I can put together a few API calls (GetTickCount, Sleep, etc.) to simulate a timer, though with less chance of crashing my apps.
Cheers in advance,
Sam
-
Jan 17th, 2001, 09:13 AM
#2
_______
<?>
Are you sure it's the timer?
I have timers running on 3 different machines and I have no crash problems with any of the timers.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jan 17th, 2001, 09:21 AM
#3
Fanatic Member
There is a sample client server application which comes with VB called 'coffee'. Included with this is the source for an API based timer wrapped in a DLL called 'XTimers.vbp'.
If you don't have this on your PC email me and I will send it to you!
-
Jan 17th, 2001, 09:24 AM
#4
Thread Starter
Lively Member
The only programs I have made that crash regularly run a timer that ticks at between once every 10 seconds and every quarter of a second. In one such case I kind of expected the computer to crash because I was passing huge amounts of information through it every fraction of a second, but the one that ticks every 10 seconds really shouldn't crash.
One way to check would be to recompile the program with a custom-built API timer, but I don't know how to make one. I'll have a think, but if anyone comes up with anything then please can they tell me,
Sam
[PS. Jerry, just spotted your last post, and don't have coffee. If you could send it to me at [email protected] then I would be eternally grateful - cheers!]
-
Jan 17th, 2001, 10:12 AM
#5
_______
<?>
OK, I have heard of crashes when your interval is minuitely small and large amts of data are trying to get through.
Perhaps a pause method might work for you.
Code:
Enought to get you started
'this will pause your app for 1 min and write out to debug
'to get out of the loop press F2
'when getting out of the loop it will always do one last loop
'as the condition was true when you pressed F2 to make it false
'
'as far as I know GetTicCount resets itself after 47 days or so
'of continued operation so if you don't reboot in that time, what
'will happen should be some sort of quirt in the count
'
'for a 10 min pause you would use 600000
Option Explicit
Public x As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF2: x = True
End Select
End Sub
Private Sub Form_Load()
Form1.KeyPreview = True
End Sub
Private Sub Pause(Interval As Long)
Dim Start
Start = GetTickCount
Do While GetTickCount < Start + Interval
DoEvents
Loop
End Sub
Private Sub Command1_Click()
x = False
Do While x <> True
Pause 60000 'Pause for 1 min [1 sec = 1000]
Debug.Print Format(Now, "HH:NN:SS AM:M") 'do your stuff
Loop
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jan 17th, 2001, 10:57 AM
#6
Addicted Member
Here's some code for a timer...
=====================================================
Public Type SMPTE
hour As Byte
min As Byte
sec As Byte
frame As Byte
fps As Byte
dummy As Byte
pad(2) As Byte
End Type
Public Type MMTime
wType As Long
Units As Long
smpteVal As Long
songPtrPos As Long
End Type
Declare Function timeGetSystemTime Lib "winmm.dll" (lpTime As MMTime, ByVal uSize As Long) As Long
Public Const TIME_MS = 1
Public bmStart As Long
'===================================================================================
'Routine: StartBenchmark
'===================================================================================
'Inputs:
'
'Outputs:
'Purpose: Starts the timer. This timer is always accurate to .001 seconds
'
'Sample Call: StartBenchmark
'
'Date: 6/15/99
'===================================================================================
Public Sub StartBenchmark()
Dim MMT As MMTime
Dim lRetVal As Long
MMT.wType = TIME_MS
lRetVal = timeGetSystemTime(MMT, Len(MMT))
bmStart = MMT.Units
End Sub
'===================================================================================
'Routine: BenchmarkResults
'===================================================================================
'Inputs:
'
'Outputs: Elapsed time, accurate to .001 seconds
'Purpose: Stops the timer and passes back elapsed time sine the timer started
'
'Sample Call: msgbox BenchmarkResults & " seconds"
'
'Date: 6/15/99
'===================================================================================
Public Function BenchmarkResults() As Single
Dim MMT As MMTime
Dim lRetVal As Long
MMT.wType = TIME_MS
lRetVal = timeGetSystemTime(MMT, Len(MMT))
BenchmarkResults = (MMT.Units - bmStart) / 1000
End Function
Building A Better Body Albeit Left Out Under Intense Extrapolation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|