My service crashes during shutdown



Hello

I've written my own service (some kind of a network server). It starts quite fast and works ok. But it crashes when I try to stop it from the service manager.
I think the problem is on my site - I'm not quite sure if I understend how the service should be stopped when SERVICE_CONTROL_STOP request comes in.


Right now when I receive SERVICE_CONTROL_STOP I tell my service thread to stop (what takes some time), set status to SERVICE_STOP_PENDING and return from service control function.
In other words the service control function returns before the service thread finishes.
Can this be a source of a problem?
Should I force service control function to wait until service thread is done?


si
.