• システム開発に関わる内容をざっくりと書いていく

サービスをデバッグ実行する

1、コンソールアプリケーションにする。

2、Program.csに下記コードを記述する。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if (Environment.UserInteractive == true)
{
Service1 service1 = new Service1();
service1.StartupAndStop(new string[] { });
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
if (Environment.UserInteractive == true) { Service1 service1 = new Service1(); service1.StartupAndStop(new string[] { }); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); }
if (Environment.UserInteractive == true)
{
    Service1 service1 = new Service1();
    service1.StartupAndStop(new string[] { });
}
else
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
    new Service1()
    };
    ServiceBase.Run(ServicesToRun);
}

3、Serviceクラスに下記コードを記述する。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public void StartupAndStop(string[] args)
{
this.OnStart(args);
Console.ReadLine();
this.OnStop();
return;
}
public void StartupAndStop(string[] args) { this.OnStart(args); Console.ReadLine(); this.OnStop(); return; }
public void StartupAndStop(string[] args)
{
    this.OnStart(args);
    Console.ReadLine();
    this.OnStop();

    return;
}

4、デバッグ実行する。