Simplest service : Service « Windows « C# / CSharp Tutorial






using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;

public class Service1 : System.ServiceProcess.ServiceBase
{
  public Service1()
  {
    this.ServiceName = "MyRealService";
  }

  static void Main()
  {
    System.ServiceProcess.ServiceBase[] ServicesToRun;

    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };

    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
  }
  protected override void OnStart(string[] args)
  {
    int x = 1;
  }

  protected override void OnStop()
  {

  }
}








29.5.Service
29.5.1.Simplest service
29.5.2.Build a service by subclassing System.ServiceProcess.ServiceBase
29.5.3.Implement the service interface
29.5.4.Service control: start and stop