我得到以下内容:服务未及时响应启动或控制请求 - 错误0x8007041d [英] I am getting the following: The Service did not respond to the start or control request in a timely fashion - Error 0x8007041d

查看:345
本文介绍了我得到以下内容:服务未及时响应启动或控制请求 - 错误0x8007041d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中的调用中收到此错误:

string queryStr =从Win32_Service选择名称,PathName,StartMode,其中Name ='ArgusService2';

System.Management.ObjectQuery oQuery = new ObjectQuery(queryStr);

System.Management.ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oQuery);

foreach(System.Management.ManagementObject oOSearcher.Get()中的服务



在.Get中抛出异常并返回主题行中列出的错误。它很快就会回来(.07秒)。



任何建议都会有所帮助。

I am getting this error from a call within my code:
string queryStr = "Select Name,PathName,StartMode from Win32_Service Where Name='ArgusService2'";
System.Management.ObjectQuery oQuery = new ObjectQuery(queryStr);
System.Management.ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oQuery);
foreach (System.Management.ManagementObject oService in oSearcher.Get())

At the .Get an exception is thrown and the error listed on the Subject line is returned. It comes back very quickly (.07 seconds).

Any suggestions would be helpful.

推荐答案

输入方法(public void Main())必须在30秒内返回,否则服务似乎无法启动。



与其他类型的应用程序不同,从输入方法返回在服务中,除非没有其他运行,否则不会结束该过程。当我创建服务时,我将尽可能少地实例化,设置一个计时器事件(或第二个线程中的无限循环),然后返回到输入方法:



The entry method (public void Main()) must return within 30 seconds or the service appears to not start.

Unlike other types of application, returning from the entry method in a Service will not end the process unless there is nothing else running. When I create a service, I will instantiate as little as possible, set up a timer event (or infinite loop in a second thread), then return to the entry method:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {
        if (!Debugger.IsAttached)
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Watcher()
            };
            ServiceBase.Run(ServicesToRun);
        }
        else
        {//Just for debugging atm
            (new Watcher()).Start();
            Thread.Sleep(Timeout.Infinite);
        }
    }
}




private static Timer _timer;
       private int _timerIntervalSeconds = 10;
       private static MessageQueueParser _messageQueueParser;
       static BackgroundWorker _backgroundWorker;
       static DataParser _DataParser;

       public Watcher()
       {
           Initialize();

           CanPauseAndContinue = true;
           ServiceName = "Watcher Service";

           _timer = new Timer(_timerIntervalSeconds * 1000);
           _timer.Elapsed += OnTimerElapsed;

           _messageQueueParser = new MessageQueueParser();

           _backgroundWorker = new BackgroundWorker {WorkerSupportsCancellation = false};
           _backgroundWorker.RunWorkerCompleted += WorkerRunWorkerCompleted;
           _backgroundWorker.DoWork += WorkerThreadDoWork;

           //passively recieves api events
           _DataParser = new DataParser();

       }







private static bool _isBusy;

       void OnTimerElapsed(object sender, ElapsedEventArgs e)
       {
           if (_isBusy)
           {
               if (!_backgroundWorker.IsBusy)
                   _isBusy = false;
               return;
           }
           _isBusy = true;

           _backgroundWorker.RunWorkerAsync();

       }





这是一个扩展示例,因为我正在研究atm 。启动时会有更多与配置的互动,但概念就在那里。



希望有所帮助



不要忘记喜欢和订阅:P



This is an extended example as it's what I'm working on atm. There will be more interaction with the config on startup but the concept is there.

Hope that helps

Don't forget to like and subscribe :P


这篇关于我得到以下内容:服务未及时响应启动或控制请求 - 错误0x8007041d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆