标签:WriteLog 1053 启动 错误代码 System timer Elapsed Timers ex
原因多种:
1. service程序有bug,自行写测试方法排错。
2. service程序使用System.Configuration.ConfigurationManager类库尝试读取app.config下的配置项等
安装服务之后System.Configuration.ConfigurationManager找到的路径不再是原来的exe所在路径,故不可使用;
可以另外写xml或者Json配置文件通过Application.StartupPath或System.AppDomain.CurrentDomain.BaseDirectory读取。
3. OnStart方法响应逻辑花费过长时间,建议进行异步调用,如开启子线程或使用timer,使用timer例如:
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 //调用业务方法 26 } 27 } 28 catch (Exception ex) 29 { 30 WriteLog.SaveExceptionLog("Error:" + ex.Message); 31 } 32 }
4. 检查.Net FrameWork版本。
5. 检查ProjectInstaller的serviceInstaller控件属性中的服务名称是否与启动的服务名一致。
标签:WriteLog,1053,启动,错误代码,System,timer,Elapsed,Timers,ex 来源: https://www.cnblogs.com/jnyx/p/15140894.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。