static class Program { static void Main() { #if DEBUG // Instancie une fenêtre permettant de simuler le service Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault( false ); Application.Run( new WinService() ); #else // Instancie le service ServiceBase.Run( new ServiceBase[] { new WinService() } ); #endif }
#if DEBUG public class WinService : Form #else public class WinService : ServiceBase #endif { #if DEBUG private IContainer components; #endif // Constructeur du service public WinService() { // Initialise le service InitializeComponent(); } #if DEBUG private void InitializeComponent() { ;// Ici, le code habituellement généré par le concepteur WinForm de visual studio this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WinService)); this.SuspendLayout(); // etc etc.. } #else private void InitializeComponent() { // // WinService // this.AutoLog = false; this.ServiceName = "Nom du service"; } #endif // Au démarrage du service #if DEBUG protected override void OnLoad( EventArgs e ) { #else protected override void OnStart( string[] args ) { #endif ;// Ici, le code à exécuter au démarrage du service } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question