From: Henning on
Hi all,

I'm about to run a Standard Exe app as a Service using NTSvc.ocx. My problem
is how to run a Timer without a Form.

I've been reading all kinds of links on Google for hours, but they all seem
to involve a Form.

I've also read that there could be a problem with CallBacks using NTSvc.ocx?

/Henning



From: GS on
Henning formulated on Monday :
> Hi all,
>
> I'm about to run a Standard Exe app as a Service using NTSvc.ocx. My problem
> is how to run a Timer without a Form.
>
> I've been reading all kinds of links on Google for hours, but they all seem
> to involve a Form.
>
> I've also read that there could be a problem with CallBacks using NTSvc.ocx?
>
> /Henning

Can you not just use a form anyway? It just needs to be loaded to work
and so why would this be a problem?

Reason I'm asking is because I'd like to do something similar.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


From: Jim Mack on
Henning wrote:
> Hi all,
>
> I'm about to run a Standard Exe app as a Service using NTSvc.ocx.
> My problem is how to run a Timer without a Form.
>
> I've been reading all kinds of links on Google for hours, but they
> all seem to involve a Form.
>
> I've also read that there could be a problem with CallBacks using
> NTSvc.ocx?

SetTimer / KillTimer / TimerProc

http://support.microsoft.com/kb/180736

I'm almost positive that system timers, unlike multimedia timers, call
back on the user's thread, so there should be no issues there.

But as another poster said, loading (not showing) a bare form with a
VB timer would be a lot simpler.

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"

From: Tom Shelton on
After serious thinking Henning wrote :
> Hi all,
>
> I'm about to run a Standard Exe app as a Service using NTSvc.ocx. My problem
> is how to run a Timer without a Form.
>
> I've been reading all kinds of links on Google for hours, but they all seem
> to involve a Form.
>
> I've also read that there could be a problem with CallBacks using NTSvc.ocx?
>
> /Henning

A standard VB Timer needs an hWnd to operate. So, you would have to at
least load a hidden form if you want to use the standard timer.

You can use SetTimer/KillTimer has has already been suggested - but you
still need a message loop. Because of that you will probably want to
wrap it in an object that is on a background thread. I'd give you an
example but, the only example I have of using SetTimer is one I did in
C# for someone - so, it's pretty much usless to you.

Another, way would to implement something like the threaded timers in
..NET. You could create an object on a background thread - it's timer
functionality would basically just be a loop with WaitForSingleObject (
or WaitForMultipleObjects if you want to manage more then one timer at
a time). If you needed to cancel, you would basically set a flag and
signal the internal handle which would either exit or raise and event
or a callback (in VB5/6, I used to prefer to use interfaces and
callbacks for this stuff, because the performance was WAY better). I
suppose at that point you could decide if you call back async or not.
I think I would, but of course then any code you write in your timer
event better be re-entrant.

The nice thing is at least in VB6 threading model you won't have to
worry to much about syncronization.

Anyway, that's my thoughts on how I would approach it in VB.CLASSIC.
And I think I'd probably lean to using syncronization objects over
settimer...

--
Tom Shelton


From: Jim Mack on
Tom Shelton wrote:
>
> You can use SetTimer/KillTimer has has already been suggested - but
> you still need a message loop. Because of that you will probably
> want to wrap it in an object that is on a background thread.

That's the point of TimerProc callbacks -- everything operates on the
main thread and message loop. Can you demonstrate otherwise?

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"