ServiceMode
C# code Service Mode
class ServiceProgram : ServiceBase
{
public ServiceProgram()
{
InitializeComponent();
}
//private BackgroundWorker client_worker = null;
protected override void OnStart (string[] args)
{
Program.Client_main();
Program.WriteLog("Start");
}
void client_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
//Program.Client_main();
}
catch (Exception err )
{
Program.WriteLog("[error] " + err.Message + err.StackTrace);
}
if (worker.CancellationPending)
return;
}
public void Start(string[] args)
{
this.OnStart(args);
}
protected override void OnStop()
{
Program.Disconnect();
Program.WriteLog("Stop");
}
public void Stop()
{
this.OnStop();
}
private void InitializeComponent()
{
this.ServiceName = "OpcuaClient";
}
}