private static void Main(string[] args) { if (args.Any()) { string serviceName = "AIS_Enterprise_Gas"; switch (args[0]) { case "-c": var gas = new GasProcessing(); gas.GetBalance(); Console.ReadKey(); break; case "-i": if (GetServiceStatus(serviceName) != "notInstalled") { if (GetServiceStatus(serviceName) == "started") { StopService(serviceName); DeleteService(serviceName); } else if (GetServiceStatus(serviceName) == "stopped") { DeleteService(serviceName); } } InstallService(); StatrtService(serviceName); break; case "-u": DeleteService(serviceName); break; default: throw new Exception(); } } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); } }
protected override void OnStart(string[] args) { var gas = new GasProcessing(); Task.Factory.StartNew(gas.GetBalance); }