« Service et csharp » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
(Page créée avec « Category:CSharp = Create the project = # File → New → Project # Windows Service (.NET Framework) # Rename {{boxx|Service1.cs}} to {{boxx|MyService.cs}} # Double-cl… »)
 
Aucun résumé des modifications
Ligne 5 : Ligne 5 :
# Rename {{boxx|Service1.cs}} to {{boxx|MyService.cs}}
# Rename {{boxx|Service1.cs}} to {{boxx|MyService.cs}}
# Double-click on {{boxx|MyService.cs}} to open the designer → Properties → ServiceName = {{boxx|MyService}}
# Double-click on {{boxx|MyService.cs}} to open the designer → Properties → ServiceName = {{boxx|MyService}}
= Code =
<filebox fn='MyService.cs'>
public partial class MyService : ServiceBase
{
    public MyService()
    {
        InitializeComponent();
    }
    protected override void OnStart(string[] args)
    { }
    protected override void OnStop()
    { }
}
</filebox>
<filebox fn='Program.cs'>
static void Main()
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new WindowsCmder()
    };
    ServiceBase.Run(ServicesToRun);
}
</filebox>

Version du 11 février 2022 à 21:59

Create the project

  1. File → New → Project
  2. Windows Service (.NET Framework)
  3. Rename Service1.cs to MyService.cs
  4. Double-click on MyService.cs to open the designer → Properties → ServiceName = MyService

Code

MyService.cs
public partial class MyService : ServiceBase
{
    public MyService()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    { }

    protected override void OnStop()
    { }
}
Program.cs
static void Main()
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new WindowsCmder()
    };
    ServiceBase.Run(ServicesToRun);
}