【发布时间】:2015-03-12 12:24:19
【问题描述】:
作为第一步,我创建了 Windows 服务项目并对其进行了正确配置
在第二步中,我在项目中添加了TopShelf版本 3.1.135.0 如果我通过(F5 运行)运行我的服务,那么它正在加载顶级控制台并且服务已成功完成。
但是,当我运行它来安装并从命令提示符启动它时,我遇到了超时错误。
Topshelf.Hosts.StartHost Error: 0 : The service failed to start., System.Service
Process.TimeoutException: Time out has expired and the operation has not been co
mpleted.
public class AppService
{
LoggingService loggingService = new LoggingService(typeof(AppService).Name);
public void Start()
{
loggingService.Info("SampleService is Started");
ExtractProcess.Start();
TransformProcess.Start();
}
public void Stop()
{
loggingService.Info("SampleService is Stopped");
}
}
-- 更新代码以解决此问题
public void Start()
{
loggingService.Info("MPS.GOA.ETLService is Started");
ThreadStart myThreadDelegate = new ThreadStart(StartService);
Thread myThread = new Thread(myThreadDelegate);
myThread.Start();
}
private void StartService()
{
timer.Elapsed += new System.Timers.ElapsedEventHandler(OnElapsedTime);
timer.Interval = 60000 * ServiceIntervalInMinutes; //1 minute 60000 milliseconds
timer.Enabled = true;
Process();
}
private void Process()
{
ExtractProcess.Start();
TransformProcess.Start();
}
有什么建议吗?
【问题讨论】:
-
AppService.Start()是做什么的? -
我已经为它添加了代码。但问题是,如果我从 VS F5 服务运行正常,那么只有当我安装并运行它时才会出现超时错误
-
提取过程从网络位置读取文件并加载到数据库中
-
为什么在更新/固定的代码中需要一个计时器?
标签: c# .net windows-services topshelf