protected override void OnStart(string[] args) { strWorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); NativeFunc.Init(); frequncy = new Timer(); frequncy.Interval = NativeFunc.period * 1000; //every 30 secs frequncy.Elapsed += new System.Timers.ElapsedEventHandler(this.frequncy_Tick); frequncy.Enabled = true; NativeFunc.Bob(); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() // .WriteTo.LiterateConsole() .WriteTo.RollingFile(System.AppDomain.CurrentDomain.BaseDirectory + "logs\\tcpmon-{Date}.txt") .CreateLogger(); if (args.Length == 0) { // File.AppendAllText("c:\\temp\\mylog.txt", "Run it as a service"); // Run your service normally. Log.Information("Run it as a service"); ServiceBase[] ServicesToRun = new ServiceBase[] { new SmartFixService() }; ServiceBase.Run(ServicesToRun); } else if (args.Length == 1) { switch (args[0]) { case "-install": InstallService(); StartService(); break; case "-uninstall": StopService(); UninstallService(); break; case "-normal": NativeFunc.Init(); NativeFunc.Bob(); break; case "-testmail": System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); NativeFunc.loadSettings("settings.json"); NativeFunc.notifyAdmin(); Console.WriteLine("Done! check your email inbox or the log file"); break; default: throw new NotImplementedException(); } } }