Handle exception in ServiceBase.OnStart method
https://stackoverflow.com/questions/158772/handle-exception-on-service-startup
If the main thing you want is for the Services window to report that there was an error, from what I've tried (.net 3.5 on Windows 7), the only way to do this is by setting the ExitCode. I recommend setting it to 13816, since this results in the message, "An unknown error has occurred." See the windows error codes.
The sample below accomplishes three things.
1 - setting ExitCode results in a useful message for the end-user. It doesn't affect the Windows Application log but does include a message in the System log.
2 - Calling Stop results in a "Service successfully stopped" message in the Application log.
3 - throwing the exception results in a useful log entry in the Application log.
protected override void OnStart(string[] args) { try {
// Start your service
}
catch (Exception ex) {
// Log exception
this.ExitCode = ;
this.Stop();
throw;
} }
Handle exception in ServiceBase.OnStart method的更多相关文章
- Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getUser' in class org.uncommons.reportng.ReportMetadata threw exception class java.net.UnknownHostException :
Running TestSuite [TestNG] [WARN] Ignoring duplicate listener : org.uncommons.reportng.HTMLReporter ...
- ServiceBase.OnStart 方法
msdn 解释 派生类中实现时,在由服务控制管理器 (SCM) 或在操作系统启动时 (对于自动启动的服务) 时,将启动命令发送到服务时执行. 指定当服务启动时要执行的操作. 命名空间: Syste ...
- python3.x + selenium 3.x 遇到的问题:Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x0045E450>>
我解决了!!!from selenium import webdriverimport timedr = webdriver.Firefox(executable_path = '/Users/jin ...
- How to Handle Exception
- Exception Handling in ASP.NET Web API
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErr ...
- [转]java-Three Rules for Effective Exception Handling
主要讲java中处理异常的三个原则: 原文链接:https://today.java.net/pub/a/today/2003/12/04/exceptions.html Exceptions in ...
- Exception (2) Java Exception Handling
The Java programming language uses exceptions to handle errors and other exceptional events.An excep ...
- Exception (3) Java exception handling best practices
List Never swallow the exception in catch block Declare the specific checked exceptions that your me ...
- 一个servlet处理多个请求(使用Method的反射机制)
方法一 可以通过在请求的时候加上参数,然后在servlet中获取请求的参数,再去调用对应的方法.达到一个servlet处理多个请求的目的 test.jsp: <%@ page language= ...
随机推荐
- Android开发高手课 - 02 崩溃优化(下):应用崩溃了,你应该如何去分析?
崩溃现场 1. 崩溃信息 进程名.线程名 崩溃类型和堆栈信息 2. 系统信息 Logcat 机型.系统.厂商.CPU.ABI.Linux 版本等 设备状态:是否 root.是否模拟器.是否有 Xpos ...
- XML——读与写
XML写入 private static void writeXml() { using (XmlTextWriter xml = new XmlTextWriter(@"C:\Users\ ...
- php入门学习笔记
学习笔记[6.5-6.13] 1.常用命令 打开数据库格式: mysql -h主机地址 -u用户名 -p 重启nginx:sudo /etc/init.d/nginx restart或者service ...
- 如何利用Flashback Query 恢复误删除的数据
网上有很多关于数据回复的文章,这里整理一篇供大家参考,希望能帮助的大家! 推荐一家即时通讯云服务商:www.yun2win.com,功能包含im即时通讯.实时音视频.电子白板.屏幕共享的多种融合通讯云 ...
- java攻城狮之路--复习JDBC(利用BeanUtils、JDBC元数据编写通用的查询方法;元数据;Blob;事务;批量处理)
1.利用BeanUtils的前提得要加入以下两个jar包: commons-beanutils-1.8.0.jar commons-logging-1.1.1.jar package com.shel ...
- 3.用Redis Desktop Manager连接Redis(CentOS)
Redis Desktop Manager是Redis图形化管理工具,方便管理人员更方便直观地管理Redis数据. 然而在使用Redis Desktop Manager之前,有几个要素需要注意: 一. ...
- 如何从源码启动和编译IoTSharp
IoTSharp 项目是一个开源物联网平台,数据库使用PostgreSQL , 后端使用 Asp.Net Core 2.2 ,前端使用 vue-element-admin , 下面我们介绍如何启动项 ...
- Oracle,sqlserver,mySQl的区别和联系:
1.日期处理方式 2.对保留字和关键字的处理方式: Oracle,sqlserver,mySQl的保留字不可以用作列字段,关键字可以,但他们对关键字的处理方式又不同: Oracle:关键字作为列时:用 ...
- CF17E Palisection (回文自动机+DP)
题目传送门 题目大意:给你一个字符串,让你求出有多少对相交的回文子串 啊啊啊啊降智了,我怎么又忘了正难则反! 求相交会很难搞.把问题转化成求互不相交的回文子串再减一下就行了 先利用$PAM$求出以每个 ...
- 【hiho一下 第145周】智力竞赛
[题目链接]:http://hihocoder.com/contest/hiho145/problem/1 [题意] [题解] 设f[i][j]表示做对i道题,做错j道题能够到达的最好状态是什么; 这 ...