There are many reasons:
1. There are bugs in the service program, so write your own test methods to troubleshoot.
2. The service program uses the System.Configuration.ConfigurationManager class library to try to read the configuration items under app.config, etc.
After installing the service, the path found by System.Configuration.ConfigurationManager is no longer the path where the original exe is located, so it cannot be used;
You can also write xml or Json configuration file absolute path to read.
3. The OnStart method takes too long to respond to the logic. It is recommended to make asynchronous calls, such as opening a child thread or using a timer. For example:
1 System.Timers.Timer _timer = new System.Timers.Timer(); 2 protected override void OnStart(string[] args) 3 { 4 try 5 { 6 int _interval = 1000 * 60 * interval; 7 _timer.Interval = _interval; 8 _timer.AutoReset = true; 9 _timer.Elapsed += new System.Timers.ElapsedEventHandler(Time_Elapsed); 10 _timer.Enabled = true; 11 WriteLog.SaveInfoLog("服务已启动"); 12 } 13 catch (Exception ex) 14 { 15 WriteLog.SaveExceptionLog(ex.Message); 16 } 17 18 } 19 private void Time_Elapsed(object sender, System.Timers.ElapsedEventArgs e) 20 { 21 try 22 { 23 if (!isRun) 24 { 25 // Call business method 26 } 27 } 28 catch (Exception ex) 29 { 30 WriteLog.SaveExceptionLog( " Error: " + ex.Message); 31 } 32 }
4. Check the .Net FrameWork version.
5. Check whether the service name in the serviceInstaller control property of ProjectInstaller is consistent with the started service name.
Similar Posts:
- [Solved] scheduler Error: maximum number of running instances reached
- timer_create ,timer_settime,timer_delete
- Swift 3.0: How to solve the problem of timer circular reference
- [Solved] Kibana Startup Error: error [03:10:02.393] [warning][process] Error: Request Timeout after 30000ms
- [Solved] maven Project Compile Error: was cached in the local repository, resolution will not be reattempte
- HDFS: How to Operate API (Example)
- Java error: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Pie Component carousel Error: Instance ec_1623382451382 has been disposed (Error-Loading Change Redraw)
- Java Thread wait, notify and notifyAll Example
- Maven Error: Failed to execute goal on project xxx: Could not resolve dependencies for project