Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,
I am working a windows service. This service set on automatic. In this service I checked the File which is created on any where like on C drive (I give this path in service).

At the time of start the service I check the given file; if file is not found that time service should not be started.

In OnStop() I call the one other function.(this function is used to disconnected my server (like OPC server) when click on stop option if the server path is found.

I used the following method in OnStart()
int exitCode = 0;
System.Environment.Exit(exitCode);

Using the above method service should not started. But I got an error message
"Error 1067: The process terminated unexpectedly."
How can I handle this message or change the error message “File not found”?

Please help me.

Thanks in Advance.
Posted
Updated 15-Jun-11 20:50pm
v3

You can use File.Exists("path") to check if it is there or not, Then proceed accodingingly.
 
Share this answer
 
If you want to terminate the windows service with an error message within OnStart, then throw an unhandled exception:
throw new ApplicationException("File not found: " + strFilename);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900