【发布时间】:2016-12-31 17:38:36
【问题描述】:
我使用了一个简单的 Windows 服务来使某个方法在特定时间工作,并且它工作正常。之后我已经尝试过了:
protected override void OnStart(string[] args)
{
this.WriteToFile("Simple Service started {0}");
this.ScheduleService();
}
protected override void OnStop()
{
this.WriteToFile("Simple Service stopped {0}");
this.Schedular.Dispose();
}
private Timer Schedular;
public void ScheduleService()
{
try
{
Schedular = new Timer(new TimerCallback(SchedularCallback));
string mode = ConfigurationManager.AppSettings["Mode"].ToUpper();
this.WriteToFile("Simple Service Mode: " + mode + " {0}");
//Rest of the code here
}
catch(Exception ex)
{
WriteToFile("Simple Service Error on: {0} " + ex.Message + ex.StackTrace);
//Stop the Windows Service.
using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SimpleService"))
{
serviceController.Stop();
}
}
}
这是在一个简单的 Windows 应用程序中完成的。所以我想做的是在windows服务中调用一个web服务(在特定时间操作的特定方法)。我正在构建的应用程序是基于 Web 的,并且有点困惑如何将 Windows 服务集成到其中?我需要任何替代方案或任何建议将不胜感激。
注意:我想知道的是需要在web应用程序中为windows服务创建另一个项目还是任何其他方式来实现?
【问题讨论】:
-
是的。您的 Windows 服务需要是一个单独的项目。
-
感谢您的回复,我正在考虑@PhillipH。顺便问一下,您知道或有任何有用的教程或链接吗?
-
请看我更完整的答案。
标签: c# asp.net web-services windows-services