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 :

Trasnformer Un application Form en service


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 Trasnformer Un application Form en service
    Bonjour à tous,

    J'ai fais une application avec une windows form qui détecte l'activité de l'utilisateur sur l'écran;
    Je voudrais transformer cette application en service.
    J'ai pensée à mettre ma clase MainForm dans mon service et à créer une nouvelle instance de la classe mais cela ne fonctionne pas.
    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
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
     
     public class MainForm : System.Windows.Forms.Form
            {
                private System.Windows.Forms.Button CreateCtrlMonButton;
                private System.ComponentModel.Container components = null;
                private System.Windows.Forms.TextBox OutputTextBox;
                private System.Windows.Forms.Button DisposeMonButton;
                private System.Windows.Forms.Button NullMonVarButton;
                private System.Windows.Forms.Button EnableMonButton;
                private System.Windows.Forms.Button DisableMonButton;
                private System.Windows.Forms.Button TriggerCGButton;
                private System.Windows.Forms.GroupBox CreateOptsGroup;
                private System.Windows.Forms.ComboBox MonTypeComboBox;
                private System.Windows.Forms.Label label1;
                private System.Windows.Forms.TextBox IntervalTextBox;
                private System.Windows.Forms.CheckBox SyncCheckBox;
                private System.Windows.Forms.CheckBox MonKeyboardCheckBox;
                private System.Windows.Forms.CheckBox MonMouseCheckBox;
                private System.Windows.Forms.Button ShowMsgBoxButton;
                private System.Windows.Forms.Button ShowOtherWindowButton;
                private System.Windows.Forms.CheckBox ModalWndCheckBox;
     
                private IInactivityMonitor inactivityMonitor = null;
     
                public MainForm()
                {
                    InitializeComponent();
     
                }
     
                protected override void Dispose(bool disposing)
                {
                    if (disposing)
                    {
                        if (components != null)
                        {
                            components.Dispose();
                        }
                    }
                    base.Dispose(disposing);
                }
     
                #region Vom Windows Form-Designer generierter Code
                private void InitializeComponent()
                {
                    this.SuspendLayout();
                    // 
                    // MainForm
                    // 
                    this.ClientSize = new System.Drawing.Size(284, 262);
                    this.Name = "MainForm";
                    this.ShowIcon = true;
                    this.ShowInTaskbar = true;
                    this.TransparencyKey = System.Drawing.Color.Transparent;
                    this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                    this.ResumeLayout(false);
                    inactivityMonitor = MonitorCreator.CreateInstance(MonitorType.GlobalHookMonitor);
                    inactivityMonitor.SynchronizingObject = null;
                    inactivityMonitor.MonitorKeyboardEvents = true;
                    inactivityMonitor.MonitorMouseEvents = true;
                    inactivityMonitor.Interval = 1000;
                    inactivityMonitor.Elapsed += new ElapsedEventHandler(TimeElapsed);
                    inactivityMonitor.Reactivated += new EventHandler(Reactivated);
                    inactivityMonitor.Enabled = true;
     
                }
                #endregion
     
                [STAThread]
                static void Main()
                {
                    try
                    {
                        Application.Run(new MainForm());
     
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
     
                private void TimeElapsed(object sender, ElapsedEventArgs e)
                {
                    try
                    {
                        if (this.InvokeRequired)
                        {
                            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);
                            }
                        }
                        //  WriteOutput("Event 'Elapsed' occured (Invoke() would have been required)");
                        else
                        {
                            {
                                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);
                                }
                            }
                            //  WriteOutput("Event 'Elapsed' occured (synchronized call)");
                        }
                    }
                    catch (Exception exception)
                    {
                        //	WriteOutput("Exception occured: " + exception.Message);
                    }
                }
     
                private void Reactivated(object sender, EventArgs e)
                {
                    try
                    {
                        /* if (this.InvokeRequired) {}
                         //	WriteOutput("Event 'Reactivated' occured (Invoke() would have been required)");
                         else { }
                         //	WriteOutput("Event 'Reactivated' occured (synchronized call)");*/
                    }
                    catch (Exception exception)
                    {
                        //	WriteOutput("Exception occured: " + exception.Message);
                    }
                }
     
            }
    Comment puis je faire pour migrer mon appli?
    Merci

  2. #2
    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
    Bonjour,
    Après réflexion, j'ai pensé pour pouvoir utiliser mon application à exécuter mon fichier exe depuis mon service windows, mais je n'y'arrive pas. Mon appli ne démarre pas.
    J'utilise ce code pour cela :
    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
     
      protected override void OnContinue()
            {
                Process myProcess = new Process();
     
                try
                {
                    myProcess.StartInfo.UseShellExecute = false;
                    // You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\Users\\piafou\\Documents\\Visual Studio 2010\\Projects\\Nouveau dossier (2)\\bin\\Debug\\TestApplication.exe";
                    myProcess.StartInfo.CreateNoWindow = true;
                    myProcess.Start();
                    // This code assumes the process you are starting will terminate itself.  
                    // Given that is is started without a window so you cannot terminate it  
                    // on the desktop, it must terminate itself or you can do it programmatically 
                    // from this application using the Kill method.
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
    Voyez vous un souci dans le code, ou peut être cela ne peux pas fonctionner.
    Aidez moi svp!!
    Merci à ts!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 9
    Dernier message: 11/01/2007, 21h23
  2. [Forms]dployement application forms oracle 9i
    Par oraNabiloune dans le forum Forms
    Réponses: 1
    Dernier message: 12/12/2006, 13h00
  3. Mettre une application access en service windows
    Par stolx_10 dans le forum Access
    Réponses: 7
    Dernier message: 17/10/2006, 11h16
  4. Mettre une application access en service windows.
    Par chris_magic dans le forum Access
    Réponses: 11
    Dernier message: 11/07/2006, 15h50
  5. [Forms6i] lien URL d'une application forms
    Par bargou dans le forum Forms
    Réponses: 4
    Dernier message: 13/12/2004, 12h50

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