我正在尝试在 Windows 服务中编写简单的 wcf 服务自托管但 Windows 服务的 ServiceHandle 始终为 0
我需要使用 RegisterDeviceNotification 检测硬件更改它的参数之一是 Handle,在我的例子中是 ServiceHandle
public partial class MyService : ServiceBase, IMyService
{
private ServiceHost host;
public static void Main()
{
ServiceBase.Run(new MyService());
}
public MyService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
host = new ServiceHost(typeof(MyService), new Uri(@"net.pipe://localhost/MyService"));
host.Open();
}
catch (Exception e)
{
EventLog.WriteEntry("MyService:", e.Message);
}
}
protected override void OnStop()
{
host.Close();
}
#region IMyService Members
public void Register()
{
//Here the ServiceHost is 0
}
#endregion
}
什么会导致问题?谢谢