Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

StartServiceCtrlDispatcher hangs in Console application

365 views
Skip to first unread message

Zach

unread,
May 29, 2009, 3:30:05 PM5/29/09
to
I have a windows service which occasionally I like to run from a
command prompt. One of the very first pieces of code in the
application is this:

SERVICE_TABLE_ENTRY Dispatch[] = { {"MyService", ServiceMain}, {NULL,
NULL} };

if (!StartServiceCtrlDispatcher(Dispatch))
{
//We were started from the command line
}
else
{
//We were start through Service Control Manager
}

When started as a service there's no problems but when started from
the command line, the StartServiceCtrlDispatcher() line of code can
take up to 20 seconds to return! What is going on here that it's
waiting for?

Advice appreciated
Zach

Marc

unread,
May 30, 2009, 1:12:23 PM5/30/09
to
"Zach" <diviso...@gmail.com> a �crit dans le message de news:
6b864808-a70b-46a5...@j18g2000yql.googlegroups.com...

> When started as a service there's no problems but when started from
> the command line, the StartServiceCtrlDispatcher() line of code can
> take up to 20 seconds to return! What is going on here that it's
> waiting for?

MSDN says that :
If StartServiceCtrlDispatcher succeeds, it connects the calling thread to
the service control manager and does not return until all running services
in the process have entered the SERVICE_STOPPED state.


Zachary Turner

unread,
Jun 8, 2009, 12:22:01 PM6/8/09
to
On May 30, 12:12 pm, "Marc" <m...@tres.com> wrote:
> "Zach" <divisorthe...@gmail.com> a écrit dans le message de news:
> 6b864808-a70b-46a5-a7d0-e4761fb5d...@j18g2000yql.googlegroups.com...

>
> > When started as a service there's no problems but when started from
> > the command line, the StartServiceCtrlDispatcher() line of code can
> > take up to 20 seconds to return!  What is going on here that it's
> > waiting for?
>
> MSDN says that :
>  If StartServiceCtrlDispatcher succeeds, it connects the calling thread to
> the service control manager and does not return until all running services
> in the process have entered the SERVICE_STOPPED state.

Thanks for the response, but I'm not sure if I understand how this
applies to the question I asked. For one thing, the call isn't
succeeding because I'm running it from the console and not as a
service. If the problem could have been answered by the MSDN docs I
wouldn't have posted :(

0 new messages