您的位置:首页 > 其它

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

2013-03-05 11:47 1016 查看
重写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



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐