当Windows服务启动C#Windows服务没有执行代码
,我发现这里的解决方案,但他们并没有为我工作,我有以下的代码,它不执行。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Configuration;
using System.Threading.Tasks;
namespace TFS_JIRA_sync
{
public partial class SyncProcess : ServiceBase
{
public SyncProcess()
{
InitializeComponent();
}
private System.Timers.Timer timer = new System.Timers.Timer();
protected override void OnStart(string[] args)
{
this.timer.Interval = ScanPeriod.period * 60000; //turn minutes to miliseconds
this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);//OnTimer;
this.timer.Enabled = true;
this.timer.AutoReset = true;
this.timer.Start();
}
private void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
{
Processing proc = new Processing();
proc.doProcess();
}
protected override void OnStop()
{
}
}
}
在PROGRAMM:
using System;
using System.Collections.Generic;
using System.ServiceProcess;
using System.Threading.Tasks;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace TFS_JIRA_sync
{
static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SyncProcess()
};
ServiceBase.Run(ServicesToRun);
//Processing proc = new Processing();
//proc.doProcess();
}
}
}
当我开始评论部分 “ServiceBase [] ...” 并取消 “处理......” 在PROGRAMM类正常工作。
但是,当我的代码运行作为Windows服务 - 什么也没有发生
看起来正确(除了设置['Enabled'](https://msdn.microsoft.com/en-us/library/system.timers.timer.enabled(v = vs.110).aspx) **和**调用['开始'](https://msdn.microsoft.com/en-us/library/system.timers.timer.start(v = vs.110).aspx))。你如何确定它不是*正常工作? –
处理类我有记录器,记录执行的步骤。当我开始将我的Programm作为Win服务时,在日志中什么也没有发生 – Ilya