Windowsサービスが作成されており、そのためのインストーラが作成されています。それはインストールされ、起動されますが、その中に書いたコードは実行されません。実際にサービスウィンドウからサービスを開始すると、OnStart()関数は起動されません。 initializecomponent()も静的void main関数もありません。誰でも助けてくれます。Windowsサービスがインストールされていても動作していません
私が間違っていた箇所を教えてください。
ここにいくつかのコード行があります。 uは私が
public partial class iMArchiveService : ServiceBase
{
Boolean isArchiving = false;
public iMArchiveService()
{
MyException.CreateLog("iMArchiveService: Inside Constructor. Initializing Component");
InitializeComponent();
MyException.CreateLog("iMArchiveService: Component Initialized. Timer is set as: " + TimeMachine.Interval.ToString() + " milliseconds");
}
protected void TimeMachine_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
MyException.CreateLog("iMArchiveService: Inside Tick Try. Value of isArchiving variable before condition is: " + isArchiving.ToString());
if (!isArchiving)
isArchiving = new iM.OrderArchiving.ArchiveOrderXML().ArchiveOrderService();
MyException.CreateLog("iMArchiveService: Inside Tick Try. Value of isArchiving variable after condition is: " + isArchiving.ToString());
}
catch (Exception ex)
{
MyException.CreateLog("iMArchiveService: Inside Tick Catch :(");
}
}
protected override void OnStart(string[] args)
{
TimeMachine.Enabled = true;
MyException.CreateLog("iMArchiveService Started: " + DateTime.Now.ToString());
}
protected override void OnStop()
{
TimeMachine.Enabled = false;
MyException.CreateLog("iMArchiveService Stopped: " + DateTime.Now.ToString());
}
}
上記のコードは、サービスfile.csためである
を書かれているかのより多くを望むなら、私に知らせて
ここ
はここに私のプロジェクトのインストーラファイル
namespace iM.OrderArchivingService
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
}
}
あるInitializeComponenet機能です - ここ
private void InitializeComponent()
{
this.myServiceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.myServiceInstaller = new System.ServiceProcess.ServiceInstaller();
//
// myServiceProcessInstaller
//
this.myServiceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.myServiceProcessInstaller.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.myServiceInstaller});
this.myServiceProcessInstaller.Password = null;
this.myServiceProcessInstaller.Username = null;
//
// myServiceInstaller
//
this.myServiceInstaller.ServiceName = "iMArchiveService";
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.myServiceProcessInstaller});
}
はProgram.csのは
0ファイルですnamespace iM.OrderArchivingService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new iMArchiveService() };
ServiceBase.Run(ServicesToRun);
}
}
}
私は初期化または開始時にログに記録するコードを書いていますが、ログは作成されていません。
編集:タイマー用
コード(タイムマシン)
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.TimeMachine = new System.Timers.Timer(3600000);
//
// TimeMachine
//
this.TimeMachine.Interval = 3600000;
this.TimeMachine.Elapsed += new System.Timers.ElapsedEventHandler(TimeMachine_Elapsed);
//
// iMArchiveService
//
this.ServiceName = "iMArchiveService";
}
のthnx
TimeMachineタイマーの間隔はどのくらいですか? – Coder
はタイマーコードを追加しましたが、atleastは最初にコード化したログを書き込むべきです。ログはまたそれのために書かれていません – 1Mayur
私はそれがタイマーの問題ではないと推測します...さらにロギングは、それがprojectinstaller initialen componetet関数に到達するが、何を開始しなければならないのかを示していません。私は私の初期化関数が私のサービスベースクラスへの参照を持っている必要があることを意味する... – 1Mayur