« Service et csharp » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 42 : | Ligne 42 : | ||
# Change the Description to {{boxx|This service manages the ...}} | # Change the Description to {{boxx|This service manages the ...}} | ||
# Add text to DisplayName {{boxx|My service}} | # Add text to DisplayName {{boxx|My service}} | ||
# Set the {{boxx|StartType}} to {{boxx|Automatic}} | |||
# Select {{boxx|serviceProcessInstaller1}} → Properties → Account = {{boxx|LocalSystem}} |
Version du 11 février 2022 à 22:36
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
- A new class ProjectInstaller has been added
- Right-click on ProjectInstaller.cs → View Designer
- Change the Description to This service manages the ...
- Add text to DisplayName My service
- Set the StartType to Automatic
- Select serviceProcessInstaller1 → Properties → Account = LocalSystem