我编写了一个在 Win10 上运行的 Windows 服务,它运行得非常好,直到我决定对其进行一些更改。我重写了一些逻辑,在调试和发布配置中进行了测试,一切都很好。然后,我使用卸载了当前版本的服务installutil.exe /u %servicename.exe%
并使用再次重新安装它installutil.exe %servicename.exe%
.
由于某种原因,这个新版本无法启动,并且崩溃了错误1064。这是完整的错误文本:
Windows 无法在本地计算机上启动 %servicename% 服务。错误1064:处理控制请求时服务中发生异常。
上次安装此服务时,我遇到了一些困难,但通过更改很快就解决了这些问题Log On
特性。这一次,它不起作用了。请帮助解决这个问题。
Update 1
这是我的Main()
and OnStart()
服务方式:
Main()
static void Main()
{
#if DEBUG
var service = new SalesforceToJiraService();
service.OnDebug();
Thread.Sleep(Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SalesforceToJiraService()
};
ServiceBase.Run(ServicesToRun);
#endif
}
OnStart()
protected override void OnStart(string[] args)
{
this.ConfigureServices();
this.timer.Start();
this.logger.Information("SalesforceToJira service started.");
}
Update 2
更多代码:
ConfigureServices()
protected void ConfigureServices()
{
this.configuration = ConfigurationHelper.LoadConfiguration(ConfigurationPath);
this.logger = ConfigurationHelper.ConfigureLogger(this.configuration.Logs.LogsPath);
this.timer = ConfigurationHelper.ConfigureTimer(this.configuration.ProcessInterval.TotalMilliseconds,
(sender, eventArgs) => this.ProcessCasesAsync(sender, eventArgs).GetAwaiter().GetResult());
this.salesforceClient = new SalesforceCliClient(this.configuration.Salesforce.CliPath);
this.jiraClient = Jira.CreateRestClient(
this.configuration.Jira.Url,
this.configuration.Jira.Username,
this.configuration.Jira.Password);
}
我在用着Newtonsoft.JSON
用于反序列化 JSON 配置文件,Serilog
用于记录,System.Timers.Timer
对于周期性事件,AtlassianSDK
对于 Jira API 和一些包装器Salesforce CLI
对于 Salesforce。