zoukankan      html  css  js  c++  java
  • WCF 寄宿于Windows服务 ,可能会报的错:在系统启动时至少有一个服务或驱动程序产生错误。详细信息,请使用事件查看器查看事件日志。

    重写ProjectInstaller安装类中的Commit方法,让Windows服务完成安装后立即自动启动

    View Code
    namespace WindowService
    {
        [RunInstaller(true)]
        public partial class ProjectInstaller : System.Configuration.Install.Installer
        {
            public ProjectInstaller()
            {
                InitializeComponent();
            }
    
            /// <summary>
            /// 服务完成安装后,自动启动
            /// </summary>
            /// <param name="savedState"></param>
            public override void Commit(IDictionary savedState)
            {
             //   base.Commit(savedState);
                this.savedState = savedState;
    
                Thread th = new Thread(OnStartHost); 
                th.Start();
            }
            IDictionary savedState { get; set; }
            public void OnStartHost()
            {
                //延迟10秒启动
                Thread.Sleep(11000); //休眠10秒 
    
                base.Commit(this.savedState);
                //自启动
                ServiceController sc = new ServiceController("Aqioo WCF Windows服务");
    
                if (sc.Status.Equals(ServiceControllerStatus.Stopped))
                {
                    sc.Start();
                }
            }
        }
    }

     可能会报的错:在系统启动时至少有一个服务或驱动程序产生错误。详细信息,请使用事件查看器查看事件日志。

    解决办法:

    给System.ServiceProcess.ServiceInstalle类的实例serviceInstaller1的ServicesDependedOn 属性赋值

    this.serviceInstaller1.ServicesDependedOn = new string[] {"Network Location Awareness (NLA)"};

    ==============================================================

    Network Location Awareness (NLA):收集并保存网络配置和位置信息,并在信息改动时通知应用程序。

     可执行文件路径:C:\WINDOWS\system32\svchost.exe -k netsvcs

  • 相关阅读:
    Luogu2751 [USACO Training4.2]工序安排Job Processing
    BZOJ4653: [Noi2016]区间
    BZOJ1537: [POI2005]Aut- The Bus
    CF1041F Ray in the tube
    POJ1186 方程的解数
    Luogu2578 [ZJOI2005]九数码游戏
    BZOJ2216: [Poi2011]Lightning Conductor
    CF865D Buy Low Sell High
    BZOJ1577: [Usaco2009 Feb]庙会捷运Fair Shuttle
    几类区间覆盖
  • 原文地址:https://www.cnblogs.com/yonsy/p/2944047.html
Copyright © 2011-2022 走看看