locked
Error 1067 while stopping the windows service RRS feed

  • Question

  • Hi,

    I'm getting an error while stopping the windows service developed in C#. It says:

    Could not stop the Service1 service on local computer

    Error 1067: The process terminated unexpectedly.

    But still the service is getting stopped.

    Can anybody suggest how it can be avoided?

    Thanks

    • Moved by Paul Zhou Thursday, September 8, 2011 8:55 AM (From:.NET Base Class Library)
    Tuesday, September 6, 2011 6:55 AM

Answers

  • Don't do this. When Service Controller see the process return non-zero return code, it'll treat that as signal of something abnormal happened.

    Also, you're encouraged to do proper cleanup (e.g.: stop all the timers,  send abort to all worker threads and wait them to return, etc.) instead of relying .NET runtime to take care of these for you, especially if your service somehow used some unmanaged resource that the runtime has no idea of.

    Wednesday, September 7, 2011 1:16 AM
    Answerer
  • I agree with what @Cheong00 has said. You should avoid using Environment.Exit(-1) call in your OnStop() method. BTW, what is the reason behind calling it?
    --Abhimanyu
    Click the 'Vote as Helpful' arrow if this post was helpful.
    Wednesday, September 7, 2011 4:19 AM

All replies

  • There may be exception thrown during service stop. Show us your OnStop() method. 

    Also, you may want to use a try...catch... block to log what happened during service stop.

    Tuesday, September 6, 2011 8:29 AM
    Answerer
  • Hi

    Did you went through EventViewer for error information?


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    Tuesday, September 6, 2011 9:03 AM
  • OnStop() Method has only one statement

    Environment

     

    .Exit(-1);

    and I have placed it in try-catch block.

    But still it is throwing error in a message box when I manually stop the service in the services.msc window.


    • Edited by Navyatha Tuesday, September 6, 2011 9:34 AM
    Tuesday, September 6, 2011 9:27 AM
  • EventViewer has errors logged while stopping the service. It says:

    The Service1 service terminated unexpectedly. It has done this 1 time(s).

    Source being Service Control Manager.

    Tuesday, September 6, 2011 9:32 AM
  • Don't do this. When Service Controller see the process return non-zero return code, it'll treat that as signal of something abnormal happened.

    Also, you're encouraged to do proper cleanup (e.g.: stop all the timers,  send abort to all worker threads and wait them to return, etc.) instead of relying .NET runtime to take care of these for you, especially if your service somehow used some unmanaged resource that the runtime has no idea of.

    Wednesday, September 7, 2011 1:16 AM
    Answerer
  • I agree with what @Cheong00 has said. You should avoid using Environment.Exit(-1) call in your OnStop() method. BTW, what is the reason behind calling it?
    --Abhimanyu
    Click the 'Vote as Helpful' arrow if this post was helpful.
    Wednesday, September 7, 2011 4:19 AM