From: Tony Johansson on
Hi!

Here is some text from e-learning about windows services.
"If you want to pause and restart the Windows service application, you must
set the CanPauseAndContinue property to True. If this property is set to
True, you should override the OnPause and OnContinue methods.
However, if the OnPause method releases all the resources in the OnStart
method, it functions as the OnStop method. You can pause only a portion of
the work that the service perform while the service perform the remaining
activities normally."

Now to my question what in meant by the last row when it says
"You can pause only a portion of the work that the service perform while the
service perform the remaining activities normally."

I mean that if you for example use a timer in the OnStart where you set the
Enable proprty to true you might set the Enable proprty to false in the
OnPause and then in the OnContinue set the Enable property to true again.
This is how I understand how OnPause would work.

//Tony


From: Jeff Johnson on
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
news:ODCU7246KHA.4508(a)TK2MSFTNGP06.phx.gbl...

> Here is some text from e-learning about windows services.
> "If you want to pause and restart the Windows service application, you
> must set the CanPauseAndContinue property to True. If this property is set
> to True, you should override the OnPause and OnContinue methods.
> However, if the OnPause method releases all the resources in the OnStart
> method, it functions as the OnStop method. You can pause only a portion of
> the work that the service perform while the service perform the remaining
> activities normally."
>
> Now to my question what in meant by the last row when it says
> "You can pause only a portion of the work that the service perform while
> the service perform the remaining activities normally."

Wow, yet another piece of bad wording from this book.

What it's saying here is ultimately some ridiculously obvious stuff: you
can't stop EVERYTHING in your service. Something must continue to execute at
some level or the service would not be able to come out of its paused state.
In other words, the Windows message loop is still going to run. Well, duh.

> I mean that if you for example use a timer in the OnStart where you set
> the Enable proprty to true you might set the Enable proprty to false in
> the OnPause and then in the OnContinue set the Enable property to true
> again.
> This is how I understand how OnPause would work.

Yes, you have it right. Another thing you can do is to create a class-level
(or perhaps global) WaitHandle (like a ManualResetEvent) and sprinkle a
bunch of WaitOne() calls throughout your code. Then, in the OnPause event
you could Reset() the object (which will cause any call to WaitOne() to
block) and in the OnContinue event you can Set() it.


From: Jeff Johnson on
"Jeff Johnson" <i.get(a)enough.spam> wrote in message
news:e9szEJ56KHA.5464(a)TK2MSFTNGP05.phx.gbl...

> In other words, the Windows message loop is still going to run.

I probably should have said "or whatever a service's equivalent is." I'm not
sure I've ever written a Windows service in C so I don't know if it actually
has a message pump or not, but you should get the gist of what I was saying
in my original reply.


From: Patrice on
> "You can pause only a portion of the work that the service perform while
> the service perform the remaining activities normally."

As you code what happens in OnPause/OnStart, IMO they just meant that you
can do pretty much what you want here...

For example, if your service has a request queue, when the service is paused
you could refuse new requests but keep processing already queued requests
(that is a "portion of the work" is paused while "remaining activities"
keeps going on).

--
Patrice


From: Jeff Johnson on
"Patrice" <http://www.chez.com/scribe/> wrote in message
news:uAptCJ76KHA.356(a)TK2MSFTNGP05.phx.gbl...

>> "You can pause only a portion of the work that the service perform while
>> the service perform the remaining activities normally."
>
> As you code what happens in OnPause/OnStart, IMO they just meant that you
> can do pretty much what you want here...
>
> For example, if your service has a request queue, when the service is
> paused you could refuse new requests but keep processing already queued
> requests (that is a "portion of the work" is paused while "remaining
> activities" keeps going on).

You COULD do that but as a user I would not in any way, shape, or form
expect that to be what happens when a service is paused. I would expect all
"normal" work to stop and the only thing to conitnue working in the service
would be the mechanism to listen for a resume/continue signal.

Decent possible explanation, though.