Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a service within the OnStart method?

I'm writing a windows service in .net 2.0.

What should I do within the OnStart() method if for some reason I don't want my service to start? Can I simply call the Stop() method of the base class (ServiceBase)? I've tried that and am getting some funny memory access exceptions. Is it required to start a separate thread to call the Stop() method?

like image 326
Rory Avatar asked May 20 '09 11:05

Rory


1 Answers

Why do you want to do that? If there's an error, log it in event log and throw an exception. Your service won't be started and the user will be informed that something bad happened.

like image 103
mmx Avatar answered Nov 15 '22 06:11

mmx