« Service et csharp » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
(→Code) |
||
Ligne 29 : | Ligne 29 : | ||
ServicesToRun = new ServiceBase[] | ServicesToRun = new ServiceBase[] | ||
{ | { | ||
new | new MyService() | ||
}; | }; | ||
ServiceBase.Run(ServicesToRun); | ServiceBase.Run(ServicesToRun); | ||
} | } | ||
</filebox> | </filebox> |
Version du 11 février 2022 à 21:59
Create the project
- File → New → Project
- Windows Service (.NET Framework)
- Rename Service1.cs to MyService.cs
- 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 MyService() }; ServiceBase.Run(ServicesToRun); } |