Service et csharp
De Banane Atomic
Aller à la navigationAller à la recherche
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); } |
Installer
- Right-click on MyService.cs → View Designer
- Right-click on the background → Add Installer