Bonjour,
J'ai fait un petit service windows, et j'aimerais pouvoir detecter si une session est ouverte ou fermée.
Voici ce que j'ai fait pour le moment :
Le problème est que mon evenement n'est jamais déclenché, que je verrouille ma session, que je la deverrouille, que je l'ouvre ou la ferme.
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 public partial class timeControlSF2 : ServiceBase { private static bool sessionOpen = false; ... public timeControlSF2() { InitializeComponent(); ... SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch); } ... void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e) { System.Windows.MessageBox.Show("raison: "+e.Reason.ToString(), "tests", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.None, System.Windows.MessageBoxResult.OK, System.Windows.MessageBoxOptions.ServiceNotification); switch (e.Reason) { case SessionSwitchReason.SessionLock: sessionOpen = false; break; case SessionSwitchReason.SessionLogoff: sessionOpen = false; this.mess.Visible = false; this.mess.mess.check = true; break; case SessionSwitchReason.SessionLogon: sessionOpen = true; break; case SessionSwitchReason.SessionUnlock: sessionOpen = true; break; } }
Partager