IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Service windows detéction inactivité utilisateur


Sujet :

C#

  1. #1
    Membre régulier
    Inscrit en
    Janvier 2008
    Messages
    285
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 285
    Points : 91
    Points
    91
    Par défaut Service windows detéction inactivité utilisateur
    Bonjour,

    J'ai un petit problème mon évènement de temps, n'est jamais déclenché?
    voici le code :
    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using Microsoft.Win32;
    using UserInactivityMonitoring;
    using System.Collections;
    using System.Timers;
    using System.Management;
     
    namespace WindowsService1
    {
        public partial class ServiceCIBuilder : ServiceBase
        {
     
            private IInactivityMonitor inactivityMonitor = null;
     
            private ManagementEventWatcher ManagementEventWatcher = null;
     
            public ServiceCIBuilder()
            {
     
                     InitializeComponent();
                     }
     
            protected override void OnStart(string[] args)
            {
            //    EventLog.WriteEntry("My simple service started.");
                IdleWacth_init();
            }
     
            protected override void OnStop()
            {
                ManagementEventWatcher.Stop();
            }
     
     
            private void IdleWacth_init()
            {
     
                EventLog.WriteEntry("init8");
                EventLog.WriteEntry(MonitorType.DefaultMonitor.ToString());
                inactivityMonitor = MonitorCreator.CreateInstance(MonitorType.DefaultMonitor);
     
                inactivityMonitor.Elapsed += new ElapsedEventHandler(TimeElapsed);
     
                inactivityMonitor.MonitorKeyboardEvents = true;
                inactivityMonitor.MonitorMouseEvents = true;
     
                inactivityMonitor.Interval = 10000;
     
     
                inactivityMonitor.Enabled = true;
     
     
     
              //  inactivityMonitor.SynchronizingObject = inactivityMonitor;
     
     
                //   inactivityMonitor.Reactivated += new EventHandler(Reactivated);
     
                EventLog.WriteEntry("init5");
     
            }
            private void TimeElapsed(object sender, ElapsedEventArgs e)
            {
                EventLog.WriteEntry("init2");
                try
                {
                    if (this.inactivityMonitor.MonitorKeyboardEvents == false && this.inactivityMonitor.MonitorKeyboardEvents==false)
                    {
                        Process[] myProcesses;
     
                        // Returns array containing all instances of Solitaire
                        myProcesses = Process.GetProcessesByName("Calc");
     
                        if (myProcesses.Length > 0)
                        {
     
                            foreach (Process myProcess in myProcesses)
                            {
     
                                myProcess.Kill();
     
                            }
                            //       RestartService(this.ServiceName, 5000);
                        }
                    }
     
                }
                catch (Exception exception)
                {
                    //  WriteOutput("Exception occured: " + exception.Message);
                }
            }
    }
    Ce code peut-il marché? Quelles sont les erreurs?

  2. #2
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2005
    Messages
    700
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2005
    Messages : 700
    Points : 488
    Points
    488
    Par défaut
    ne manquerait il pas un Start()
    quelque part?

  3. #3
    Membre régulier
    Inscrit en
    Janvier 2008
    Messages
    285
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 285
    Points : 91
    Points
    91
    Par défaut
    Oui il doit manquer quelques chose pour démarrer l'attente de lévènémént. Un start() ou autre chose. Mon service est bien démarré.
    La question que je me pose c'est comment démarrer, déclencher évènement, ou l'intervalle.

Discussions similaires

  1. Interface utilisateur et Service Window
    Par dalkar69 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 28/10/2009, 21h13
  2. Réponses: 1
    Dernier message: 03/08/2008, 16h59
  3. Réponses: 1
    Dernier message: 12/06/2008, 12h24
  4. [VB6]Arreter un service windows
    Par bouboussjunior dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 04/10/2004, 17h03
  5. [C#] Icône, barre des tâches et Service Windows
    Par SErhio dans le forum Windows Forms
    Réponses: 17
    Dernier message: 03/09/2004, 12h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo