Convert a working Console Application to a working Windows Service

MrFawlty used Ask the Experts™

I have a console application that communicates with an exchange webservice in order to subscribe to new mail events, when a new mail is received the mail is processed and entered into a SQL DB. I've been trying (and failing) to convert this app into a working Windows Service. Either it starts and stops immediately or I get a FileNotFoundException in the Main() but all seems in order there so far as I can tell.

Any pointers? I have been googling qutie fervently but nothing has really helped me so far.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Maybe the problem is that the console application fails as soon as it starts. Can you please post the code in the sub Main()?
Éric MoreauSenior .Net Consultant
Top Expert 2016

the service needs to be instantiated in the first 30 seconds. otherwise it stops. you should add tracing to your service to see what it does (
1.) If you run the service under a user account that is not logged in you have not access to network drives, because network drives are linked when the user logs in, even if the connection is made permanent. Permanent only means "auto reconnect at next login".

2.) There might be a problem with the user rights. Try running the service under another user account and look, if the problem is the same.

3.) Maybe you want to use functionality of a service that has not been started yet. For example if you start your service before you start the exchange server or sql server you may get an error.
Try a Thread.sleep(60000) as the first command and look, if this solves your problem.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial