Bonjour à tous!
C'est ma première application Windows en .NET (je suis plutôt Web...).
Pour un besoin strictement perso, j'ai voulu faire un service Windows.
Et je suis bloqué par un chose si simple que j'en ai honte : mon timer ne fonctionne pas dans le WinService !
Voici mon code :
Si quelqu'un pouvait me signaler ma stupide erreur ... Ca serait sympa !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public partial class AutoShare : ServiceBase { private Timer _timer = new Timer(); public AutoShare() { InitializeComponent(); AutoLog = true; ServiceName = "AutoShare"; eventLog1.Source = "AutoShare"; _timer.Tick += new EventHandler(timer_Tick); _timer.Interval = 1000; } public static void Main() { Run(new AutoShare()); } protected override void OnStart(string[] args) { AutoShareCheck.Execute(eventLog1); // est exécuté _timer.Start(); } protected override void OnStop() { _timer.Stop(); } private void timer_Tick(object sender, EventArgs e) { AutoShareCheck.Execute(eventLog1); // n'est jamais exécuté } }
@++
NeoMan
Partager