https://docs.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.onstart?view=netframework-4.7.1#System_ServiceProcess_ServiceBase_OnStart_System_String___

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的更多相关文章

  1. 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 ...

  2. ServiceBase.OnStart 方法

    msdn 解释 派生类中实现时,在由服务控制管理器 (SCM) 或在操作系统启动时 (对于自动启动的服务) 时,将启动命令发送到服务时执行. 指定当服务启动时要执行的操作. 命名空间:   Syste ...

  3. 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 ...

  4. How to Handle Exception

  5. Exception Handling in ASP.NET Web API

    public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErr ...

  6. [转]java-Three Rules for Effective Exception Handling

    主要讲java中处理异常的三个原则: 原文链接:https://today.java.net/pub/a/today/2003/12/04/exceptions.html Exceptions in ...

  7. Exception (2) Java Exception Handling

    The Java programming language uses exceptions to handle errors and other exceptional events.An excep ...

  8. Exception (3) Java exception handling best practices

    List Never swallow the exception in catch block Declare the specific checked exceptions that your me ...

  9. 一个servlet处理多个请求(使用Method的反射机制)

    方法一 可以通过在请求的时候加上参数,然后在servlet中获取请求的参数,再去调用对应的方法.达到一个servlet处理多个请求的目的 test.jsp: <%@ page language= ...

随机推荐

  1. Android 微信SDK图片分享(checkArgs fail, thumbData is invalid)

    微信官网给的Demo中.图片的分享例子他是这么描述的: String url = "http://pic2.nipic.com/20090506/1478953_125254084_2.jp ...

  2. FFmpeg编译Android版本

    FFmpeg是很好用的一个音视频库,功能强大,但是用起来并不是很方便.之前一直不想用FFmpeg,因为感觉编译太麻烦,但是到了不得不用的时候了,没办法,参考了网上大神的方法,在这里自己也记录一下方便以 ...

  3. [Windows Server 2012] 安装护卫神·主机管理系统

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装护卫神·主 ...

  4. RHEL7配置中文输入法-智能拼音

    RHEL7配置中文输入法-智能拼音 RHEL7.x(CentOS7.x)系统相对之前的6.x系统变化较大,虽然安装时选择了中文环境,但是进入系统后,在控制台及编辑器中仍无法切换输入法进行中文输入. 原 ...

  5. [问题记录]-技术学习-RocketMQ-全球集群部署问题

    一:问题场景 公司在部署全球的RocketMQ的时候,遇到亚洲区的服务器往欧洲区的RocketMQ发送消息失败的情况. 总共有出现两个问题 1:No Topic Route Info org.apac ...

  6. Render2

    https://blog.csdn.net/wf19930209/article/details/81109388

  7. inline-block兼容IE7

    { display:inline-block; *display:inblock; *zoom:1 }

  8. hdu 4876

    ZCC loves cards Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. DP背包问题小总结

    DP的背包问题可谓是最基础的DP了,分为01背包,完全背包,多重背包 01背包 装与不装是一个问题 01背包基本模型,背包的总体积为v,总共有n件物体,每件物品的体积为v[i],价值为w[i],每件物 ...

  10. 00.pip安装包

    pip安装更换镜像源 pip install 包名 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com pip导出和导入 ...