Export (0) Print
Expand All

ServiceBase.ExitCode Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the exit code for the service.

Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in system.serviceprocess.dll)

[ComVisibleAttribute(false)] 
public int ExitCode { get; set; }
/** @property */
public int get_ExitCode ()

/** @property */
public void set_ExitCode (int value)

public function get ExitCode () : int

public function set ExitCode (value : int)

Property Value

The exit code for the service.

Set the ExitCode property to a non-zero value before stopping the service to indicate an error to the Service Control Manager.

The following code example shows the use of the ExitCode property to indicate a successful exit in the implementation of the OnStop method in a class derived from ServiceBase. This code example is part of a larger example provided for the ServiceBase class.

        // Stop this service.
        protected override void OnStop()
        {
            // New in .NET Framework version 2.0.
            this.RequestAdditionalTime(4000);
            // Signal the worker thread to exit.
            if ((workerThread != null) && (workerThread.IsAlive))
            {
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnStop", DateTime.Now.ToLongTimeString() +
                    " - Stopping the service worker thread.");
#endif
                pause.Reset();
                Thread.Sleep(5000);
                workerThread.Abort();

            }
            if (workerThread != null)
            {
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnStop", DateTime.Now.ToLongTimeString() +
                    " - OnStop Worker thread state = " +
                    workerThread.ThreadState.ToString());
#endif
            }
            // Indicate a successful exit.
            this.ExitCode = 0;
        }

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft