From: Karl E. Peterson on
Brain freeze here, I guess.

I need a simple one-shot timer (non form-based). I was thinking, just
use SetTimer, then call KillTimer in the callback. But, KillTimer
fails in the callback. LastDllError=0.

What quick/easy way am I forgetting for a one-shot deal like this?
(Betting I need to go with mmTimers, but I've been staring at the
screen for too long, and need to stretch...)

Thanks... Karl

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Jim Mack on
Karl E. Peterson wrote:
> Brain freeze here, I guess.
>
> I need a simple one-shot timer (non form-based). I was thinking,
> just use SetTimer, then call KillTimer in the callback. But,
> KillTimer fails in the callback. LastDllError=0.
>
> What quick/easy way am I forgetting for a one-shot deal like this?
> (Betting I need to go with mmTimers, but I've been staring at the
> screen for too long, and need to stretch...)

Timers are low-impact. I'd just set a flag in the callback and ignore
subsequent calls. If you must kill the timer, make the ignore flag
module-level and do it in the main loop (assuming you have one) based
on that flag.

--
Jim

From: Jim Mack on
Karl E. Peterson wrote:
> Brain freeze here, I guess.
>
> I need a simple one-shot timer (non form-based). I was thinking,
> just use SetTimer, then call KillTimer in the callback. But,
> KillTimer fails in the callback. LastDllError=0.
>
> What quick/easy way am I forgetting for a one-shot deal like this?
> (Betting I need to go with mmTimers, but I've been staring at the
> screen for too long, and need to stretch...)
>
> Thanks... Karl

Of course, with an mmTimer, you can just create a one-shot and be
done.

--
Jim

From: Bob Butler on

"Karl E. Peterson" <karl(a)exmvps.org> wrote in message
news:i0gar1$ooe$1(a)news.eternal-september.org...
> Brain freeze here, I guess.
>
> I need a simple one-shot timer (non form-based). I was thinking, just use
> SetTimer, then call KillTimer in the callback. But, KillTimer fails in
> the callback. LastDllError=0.

works for me; what makes you think it is failing? KillTimer return value 0
is error, non-zero is success

Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, _
ByVal nIDEvent As Long, ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long

Public Sub StartTimer(ByVal hwnd As Long)
Dim x As Long
x = SetTimer(hwnd, 1, 2000, AddressOf TimerFunc)
Debug.Print "Start", x, Err.LastDllError
End Sub

Private Sub TimerFunc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent
As Long, ByVal dwTime As Long)
Dim x As Long
Static k As Long
k = k + 1
If k = 5 Then
x = KillTimer(hwnd, idEvent)
Debug.Print "Stop", x, Err.LastDllError
Else
Debug.Print "Fire"
End If
End Sub

From: Karl E. Peterson on
Jim Mack formulated on Wednesday :
> Karl E. Peterson wrote:
>> Brain freeze here, I guess.
>>
>> I need a simple one-shot timer (non form-based). I was thinking,
>> just use SetTimer, then call KillTimer in the callback. But,
>> KillTimer fails in the callback. LastDllError=0.
>>
>> What quick/easy way am I forgetting for a one-shot deal like this?
>> (Betting I need to go with mmTimers, but I've been staring at the
>> screen for too long, and need to stretch...)
>
> Timers are low-impact. I'd just set a flag in the callback and ignore
> subsequent calls. If you must kill the timer, make the ignore flag
> module-level and do it in the main loop (assuming you have one) based
> on that flag.

Yeah, but what I got going is already complex enough, that more flags
would just really make it all quite bizarre. And, I will want to reuse
the timer for a later one-shot. I could just leave it running, but
ideally it oughta be a very short interval on (at least) the first
callback.

--
..NET: It's About Trust!
http://vfred.mvps.org