项目代码如下

ServiceController service = new ServiceController("ModbusAgent");
service.Stop();
TimeSpan timeout = new TimeSpan();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);

按照Stackoverflow:Time out has expired and the operation has not been completed in Service manager的说法,不要对其设置服务超时

于是代码改成:

ServiceController service = new ServiceController("ModbusAgent");
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);

问题解决

System.ServiceProcess.TimeoutException: Time out has expired and the operation has not been completed.的更多相关文章

  1. System.ServiceProcess与System.Configuration.Install命名空间的介绍

    System.ServiceProcess 命名空间提供用于实现.安装和控制 Windows 服务应用程序的类.服务是长期运行的可执行文件,其运行没有用户界面 System.ServiceProces ...

  2. .net core linux环境下 System.Data.SqlClient.SqlException: Connection Timeout Expired.

    最近遇到了一个很奇葩的问题,我编写了一个.net core程序读取多个数据库数据源,进行数据同步处理.该程序在windows环境下运行完全正常,但在linux环境下运行报异常,提示 System.Da ...

  3. Windows服务 System.ServiceProcess.ServiceBase类

    一.Windows服务 1.Windows服务应用程序是一种需要长期运行的应用程序,它适合服务器环境. 2.无用户界面,任何消息都会写进Windows事件日志. 3.随计算机启动而启动,不需要用户一定 ...

  4. [ScreenOS] How to manually generate a new system self-signed certificate to replace the expired system self-signed certificate without resetting the firewall

    SUMMARY: This article provides information on how to manually generate a new system self-signed cert ...

  5. dotnet 修复找不到 System.ServiceProcess 定义

    本文告诉大家如果复制网上一段代码发现 System.ServiceProcess 提示找不到方法或定义,需要手动添加引用 例如下面一段代码 using System.ServiceProcess; p ...

  6. error: could not create '/System/Library/Frameworks/Python.framework/Versions/2.7/share': Operation not permitted

    参考: Python pip安装模块报错 Mac升级到EI Captain之后pip install 无法使用问题 error: could not create '/System/Library/F ...

  7. 解决报错"Your security system have blocked an application with expired or not yet valid certificate from running"

    方法如下: Go to Control Panel Java in the Security tab click the "Edit Site List-" button clic ...

  8. Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Services

    本文内容为转载,供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - Chapter 39 Windows Servi ...

  9. C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(下)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(下)),不对的地方欢迎指出与交流. 章节出自<Professional C ...

随机推荐

  1. 获取jdk支持的编码类型

    //获取jdk支持的编码类型 Map<String,Charset> maps = Charset.availableCharsets(); for(Map.Entry<String ...

  2. ANg-基础概念

    分类 机器学习可以分为两类:监督学习(Supervised Learning)和无监督学习(Unsupervised Learning) 监督学习 Supervised Learning 监督学习是从 ...

  3. Hibernate学习笔记3.3(Hibernate组建映射2)

    多对多 相当于一个老师可以教多个学生,一个学生也可以有多个老师 数据表中都是再设计一个表寸相关的id 1.多对多单向 1annotation Student.java package com.bjsx ...

  4. C#自制Web 服务器开发:用C#开发自己的Web服务器

    当输入: GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: zh-CN User-Agent: ...

  5. SQL Server 2008读取域帐户信息

    参考:http://www.pawlowski.cz/2011/04/querying-active-directory-sql-server-t-sql/ 1.建立  link server . u ...

  6. 编程四剑客awk

    awk  'pattern +{action}' file (1)AWK基本语法参数详解 a:单引号 ''是为了和shell命令区分开: b:大括号{}表示一个命令分组: c:pattern 是一个过 ...

  7. 用Lucene4.5对中文文本建立索引

    这里需要完成一个能对txt文本建立索引,并能完成检索查询.完成这个功能,使用的是Lucene4.5,同时使用其自带的中文分析器. 准备工作是在一个文件夹里面建一些txt文件,这是我的文件结构: 首先要 ...

  8. spark dataframe操作集锦(提取前几行,合并,入库等)

    https://blog.csdn.net/sparkexpert/article/details/51042970 spark dataframe派生于RDD类,但是提供了非常强大的数据操作功能.当 ...

  9. linux 挂载磁盘

    挂在磁盘操作(还有一个300G的盘没显示出来): [root@iZgo67bo9s3uaijzqrgbaxZ ori]# df -h  Filesystem            Size  Used ...

  10. 导出pdf

    document.getElementById("exportSiteInfoTemp").onclick = function() { var thisMinheight=$(& ...