ServiceBase::OnStart Method (array<String^>^)
When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts.
Assembly: System.ServiceProcess (in System.ServiceProcess.dll)
Useto specify the processing that occurs when the service receives a Start command. is the method in which you specify the behavior of the service. can take arguments as a way to pass data, but this usage is rare.
Do not use the constructor to perform processing that should be in OnStop releases resources allocated in the constructor rather than in , the needed resources would not be created again the second time the service is called.. Use to handle all initialization of your service. The constructor is called when the application's executable runs, not when the service runs. The executable runs before . When you continue, for example, the constructor is not called again because the SCM already holds the object in memory. If
OnStop should both be implemented in your service class.is expected to be overridden in the derived class. For the service to be useful, and
Process initialization arguments for the service in the GetCommandLineArgs method, for example: string imagePathArgs = Environment.GetCommandLineArgs();.method, not in the Main method. The arguments in the args parameter array can be set manually in the properties window for the service in the Services console. The arguments entered in the console are not saved; they are passed to the service on a one-time basis when the service is started from the control panel. Arguments that must be present when the service is automatically started can be placed in the ImagePath string value for the service's registry key (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<service name>). You can obtain the arguments from the registry using the
Available since 1.1