简体   繁体   English

C#错误1053,服务未及时响应启动或控制请求

[英]C# Error 1053 the service did not respond to the start or control request in a timely fashion

I realize there are a ton of these posts, but none them, believe it or not, resolve my problem. 我意识到有很多这样的帖子,但不管您信不信,都可以解决我的问题。

I have the following code here that uses the ManagementEventWatcher class to kill a process from another in house app if it runs too long, which it occasionally does and kills the cpu. 我这里有以下代码,如果运行时间太长,则使用ManagementEventWatcher类从另一个内部应用程序中终止进程,该进程有时会执行并终止cpu。

Anyway, it gets this error instantaneously when starting the service. 无论如何,启动服务时它会立即收到此错误。 Nothing in the event log. 事件日志中没有任何内容。 Currently I have it testing with notepad.exe. 目前,我已经使用notepad.exe对其进行了测试。

public AppXKiller()
        {
            InitializeComponent();

            this.ServiceName = "AppXKiller";
            this.EventLog.Log = "Application";

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.
            this.CanHandlePowerEvent = true;
            this.CanHandleSessionChangeEvent = true;
            this.CanPauseAndContinue = true;
            this.CanShutdown = true;
            this.CanStop = true;

        }

        static void Main()
        {
            ServiceBase.Run(new AppXKiller());
        }

        protected override void OnStart(string[] args)
        {
            registerWatcher();
        }

        protected override void OnContinue()
        {
            base.OnContinue();
        }

        public void registerWatcher()
        {
            string pol = "2";
            string appName = "notepad.exe";

            string queryString =
                "SELECT *" +
                "  FROM __InstanceOperationEvent " +
                "WITHIN  " + pol +
                " WHERE TargetInstance ISA 'Win32_Process' " +
                "   AND TargetInstance.Name = '" + appName + "'";

            // You could replace the dot by a machine name to watch to that machine
            string scope = @"\\.\root\CIMV2";

            // create the watcher and start to listen
            ManagementEventWatcher watcher = new ManagementEventWatcher(scope, queryString);
            watcher.EventArrived += new EventArrivedEventHandler(this.OnEventArrived);
            watcher.Start();
        }

        private void OnEventArrived(object sender, EventArrivedEventArgs e)
        {
            Thread.Sleep(20000);
            Process[] localByName = Process.GetProcessesByName("notepad");

            if (localByName.Length > 0)
            {
                localByName[0].Kill();
            }
        }

        protected override void OnStop()
        {

        }
    }

Turns out that the application has to be the release version of the build, not the debug version. 原来,该应用程序必须是内部版本,而不是调试版本。 This makes no sense but oh well. 这没有任何意义,但是很好。 I guess if I want to test and debug the app I have to do it in release mode. 我想我是否要测试和调试应用程序,必须在发布模式下进行。

  1. Choose Release from the drop down menu up top (somewhere under tools depending on the size of your screen). 从顶部的下拉菜单中选择“释放”(取决于屏幕的大小,在工具下的某个位置)。 It probably says debug. 它可能说调试。
  2. Build the app. 生成应用。
  3. Install the service from the release folder. 从发布文件夹安装服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 1053 服务没有及时响应启动或控制请求 - Error 1053 the service did not respond to the start or control request in a timely fashion 错误1053:服务未及时响应启动或控制请求 - Error 1053: the service did not respond to the start or control request in a timely fashion Windows服务无法启动'错误1053:服务未及时响应启动或控制请求' - Windows Service won't start 'Error 1053: The service did not respond to the start or control request in timely fashion' 启动服务:“错误1053:服务未及时响应启动或控制请求” - Starting a service: “Error 1053: The service did not respond to the start or control request in a timely fashion” 错误 1053:安装并运行 WCF 服务时,服务未及时响应启动或控制请求 - Error 1053: The service did not respond to the start or control request in a timely fashion, when intalled and ran a WCF service 发生错误1053,服务未及时响应启动或控制请求 - Im getting Error 1053 the service did not respond to the start or control request in a timely fashion 错误 1053:服务没有使用 FileSystemWatcher 及时响应启动或控制请求 - Error 1053:The service did not respond to start or control request in timely fashion with FileSystemWatcher 1053 windows服务没有及时响应 - 1053 windows service did not respond in timely fashion 安装Windows服务时出错 - 服务未及时响应启动或控制请求 - Error installing Windows service — The service did not respond to the start or control request in a timely fashion 服务错误1053:无法及时启动 - Service Error 1053: Could not start in timely fashion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM