Class WindowsService
Class which allows to start application as Windows service.
Inheritance
Namespace: Nevatech.Vsb.Agent
Assembly: Nevatech.Vsb.Agent.dll
Syntax
public class WindowsService : ServiceBase
Constructors
WindowsService()
Initializes new instance.
Declaration
public WindowsService()
Fields
Name
Gets the Agent Service default system name.
Declaration
public const string Name = "Nevatech.Vsb.Agent"
Field Value
Type | Description |
---|---|
System.String |
Methods
Dispose(Boolean)
Clean up any resources being used.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | True if managed resources should be disposed; otherwise, false. |
Install()
Installs Agent Service and configure it to run under LocalSystem account and start automatically.
Declaration
public static void Install()
Install(ServiceAccount, String, String, ServiceStartMode, String, String, String)
Installs Agent Service on local machine.
Declaration
public static void Install(ServiceAccount accountType, string userName, string password, ServiceStartMode startMode, string logFileName, string serviceName = "Nevatech.Vsb.Agent", string parameters = null)
Parameters
Type | Name | Description |
---|---|---|
System.ServiceProcess.ServiceAccount | accountType | Type of Windows account that will be used to execute this service. |
System.String | userName | If user account is used, specifies user name and domain of Windows user. |
System.String | password | If user account is used, specifies password of Windows user. |
System.ServiceProcess.ServiceStartMode | startMode | Specifies the start mode of the service. |
System.String | logFileName | Name of the file that will be used to write messages during installation process. If Null, no log file will be used. |
System.String | serviceName | System name of the service, if not default name is used. |
System.String | parameters | Command line arguments to be added to the service executable. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown, if service is being configured under user account and user name or password is not provided. |
System.InvalidOperationException | Thrown, if service has already been installed on local machine. |
Install(String, String)
Installs Agent Service and configure it to run under LocalSystem account and start automatically.
Declaration
public static void Install(string logFileName, string serviceName = "Nevatech.Vsb.Agent")
Parameters
Type | Name | Description |
---|---|---|
System.String | logFileName | Name of the file that will be used to write messages during installation process. If Null, no log file will be used. |
System.String | serviceName | System name of the service, if not default name is used. |
IsInstalled(String)
Returns the flag that indicates, if Management Service is installed on the local machine.
Declaration
public static bool IsInstalled(string serviceName = "Nevatech.Vsb.Agent")
Parameters
Type | Name | Description |
---|---|---|
System.String | serviceName | System name of the service, if not default name is used. |
Returns
Type | Description |
---|---|
System.Boolean | True, if service has been installed. False, otherwise. |
IsStarted(String)
Returns the flag that indicates, if Management Service is running on the local machine.
Declaration
public static bool IsStarted(string serviceName = "Nevatech.Vsb.Agent")
Parameters
Type | Name | Description |
---|---|---|
System.String | serviceName | System name of the service, if not default name is used. |
Returns
Type | Description |
---|---|
System.Boolean | True, if service is running. False, otherwise. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown, if service is not installed on local machine. |
OnStart(String[])
Executes, when Start command is sent to the service by Windows Service Manager. Starts all configured service tasks.
Declaration
protected override void OnStart(string[] args)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | args | Not used. |
OnStop()
Executes, when Stop command is sent to the service by Windows Service Manager. Stops all currently running service tasks.
Declaration
protected override void OnStop()
Start(TimeSpan, String)
Starts Agent Service Windows service.
Declaration
public static void Start(TimeSpan timeout, string serviceName = "Nevatech.Vsb.Agent")
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | timeout | Specifies how long system should wait for service to start. If timeout expires, System.ServiceProcess.TimeoutException will be thrown. |
System.String | serviceName | System name of the service, if not default name is used. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown, if service is not installed on local machine. |
Stop(TimeSpan, String)
Stops Agent Service Windows service.
Declaration
public static void Stop(TimeSpan timeout, string serviceName = "Nevatech.Vsb.Agent")
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | timeout | Specifies how long system should wait for service to stop. If timeout expires, System.ServiceProcess.TimeoutException will be thrown. |
System.String | serviceName | System name of the service, if not default name is used. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown, if service is not installed on local machine. |
Uninstall()
Uninstall Agent Service from local machine.
Declaration
public static void Uninstall()
Uninstall(String, String)
Uninstall Agent Service from local machine.
Declaration
public static void Uninstall(string logFileName, string serviceName = "Nevatech.Vsb.Agent")
Parameters
Type | Name | Description |
---|---|---|
System.String | logFileName | Name of the file that will be used to write messages during uninstallation process. If Null, no log file will be used. |
System.String | serviceName | System name of the service, if not default name is used. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown, if service is not installed on local machine. |