私はWindowsサービスC#で新しいです。クラスArchiveAutomationAdministrator
を持っているJobAdminLib
と呼ばれるクラスライブラリがあります。このクラスにはCountJobs()
というメソッドがあります。私はスケジュールされた時間間隔でこの特定のメソッドを実行するWindowsサービスを作成しました。しかし、それは私にとってはうまくいかないようです。ログレポートは実行中であることを示していますが、そのメソッドが実行するはずの機能は動作していません。 Windowsサーバは、それが
[OK]を窓に行けば
を実行する権限を持っている場合は、次の参照Windowsサービスメソッドが動作しない
public class ArchiveAutomationAdministrator
{
JobRepository repository = new JobRepository();
public IEnumerable<LiveJobs> GetCurrentlyRetentionJobs(Func<LiveJobs, bool>
criteria = null)
{
return from job in repository.GetCurrentlyRetentionJobs() select job;
}
public void countJobs()
{
var count = from job in repository.GetCurrentlyRetentionJobs() select job;
int[] JobCount = new int[count.Count()];
for (int i = 1; i <= JobCount.Length; i++)
{
string jobnumber = repository.GetCurrentlyRetentionJobs().First().JobNumber;
JobAdministrator admin = new JobAdministrator(repository);
admin.ArchiveJob(jobnumber);
}
}
}
ため
私が付属しているコードは、私のWindowsサービス
public partial class Scheduler : ServiceBase
{
private Timer timer1 = null;
public Scheduler()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
timer1 = new Timer();
this.timer1.Interval = 5000;
this.timer1.Elapsed += new
System.Timers.ElapsedEventHandler(this.timer1_Tick);
timer1.Enabled = true;
Library.WriteErrorLog("test windows service started");
}
public void timer1_Tick(object sender, ElapsedEventArgs e)
{
this.task();
Library.WriteErrorLog("Job running successfully");
}
protected override void OnStop()
{
timer1.Enabled = false;
Library.WriteErrorLog("Service Stopped");
}
public void task()
{
Library.WriteErrorLog("Inside task");
ArchiveAutomationAdministrator admin = new ArchiveAutomationAdministrator();
admin.countJobs();
}
}
コードをインデントすると、読みやすくなります。 –
コードをインデントしてください! –
合計は読めません。編集提案を受け入れてください。 –