當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