我有一个使用 installutil 成功安装的 Windows 服务,但是当我运行它时,我收到一条错误消息,指出该服务无法启动,因为它未能及时响应。在事件查看器中,我可以看到此错误。
Application: AuctionControl.Service.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: Microsoft.Practices.Unity.ResolutionFailedException
Stack:
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(System.Type, System.Object, System.String, System.Collections.Generic.IEnumerable`1<Microsoft.Practices.Unity.ResolverOverride>)
at Microsoft.Practices.Unity.UnityContainer.Resolve(System.Type, System.String, Microsoft.Practices.Unity.ResolverOverride[])
at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](Microsoft.Practices.Unity.IUnityContainer, Microsoft.Practices.Unity.ResolverOverride[])
at AuctionControl.Service.Service1..ctor()
at AuctionControl.Service.Program.Main()
我的代码如下
using System.ServiceProcess;
using Microsoft.Practices.Unity;
namespace AuctionControl.Service
{
public partial class Service1 : ServiceBase
{
#region Constructor(s)
public Service1()
{
InitializeComponent();
_container = new UnityContainer();
_auctionControl = _container.Resolve<Services.Engine.AuctionControl>();
}
#endregion
#region Fields
private readonly Services.Engine.AuctionControl _auctionControl;
private readonly UnityContainer _container;
#endregion
protected override void OnStart(string[] args)
{
_auctionControl.StartAuctionControl();
}
protected override void OnStop()
{
_auctionControl.StopAuctionControl();
}
}
}