2017-10-02 3 views
0

J'ai tellement confus Pourquoi mon service Windows ne démarre pas! Mon service ne démarre pas c'est un travail plus tard, mais maintenant ne fonctionne pas quelqu'un ont solution à ce problème MY Exception is "Impossible de démarrer le service sur l'ordinateur". '. " et My innerExceoption est "Le service n'a pas répondu au démarrage ou au contrôle en temps opportun."Impossible de démarrer le service <MyService> sur l'ordinateur '.' C#

J'observe UAC (User Access Control) dans les fenêtres de mon atelier visuel est géré comme admin et service Avant de commencer installer Service par args dans la principale méthode !

using System; 
using System.Linq; 
using System.Reflection; 
using System.ServiceProcess; 
using System.Windows.Forms; 
namespace BotTelegram 
     { 
     static void Main(string [] args) 
       {  
      if (args.Contains("-i")) 
          { 
           System.Configuration.Install.AssemblyInstaller installer = 
            new System.Configuration.Install.AssemblyInstaller(Assembly.GetExecutingAssembly().Location, null) 
            { 
             UseNewContext = true 
            }; 
           installer.Install(null); 
           installer.Commit(null); 
           if (!args.Contains("nomessage")) 
            System.Windows.Forms.MessageBox.Show(@"Installed Successfully!"); 
           Console.WriteLine(@"Installed Successfully!"); 
           return; 
          } 
          if (args.Contains("-u")) 
          { 
           System.Configuration.Install.AssemblyInstaller installer = 
            new System.Configuration.Install.AssemblyInstaller(Assembly.GetExecutingAssembly().Location, null) 
            { 
             UseNewContext = true 
            }; 
           installer.Uninstall(null); 
           if (!args.Contains("nomessage")) 
            System.Windows.Forms.MessageBox.Show(@"Removed Successfully!"); 
           Console.WriteLine(@"Removed Successfully!"); 
           return; 
          } 
          if (args.Contains("-s1")) 
          { 
           var service = new ServiceController("PriceCheckerService", "."); 
           try 
           { 
            if (service.Status == ServiceControllerStatus.Stopped) 
            { 
             service.Start(); 
             if (!args.Contains("nomessage")) 
              System.Windows.Forms.MessageBox.Show(@"Start Service!!"); 
             return; 
            } 

           } 

           finally 
           { 
            service.Close(); 
           } 
           try 
           { 
            if (service.Status == ServiceControllerStatus.Running) 
            { 
             if (service.CanStop) 
             { 
              service.Stop(); 
              if (!args.Contains("nomessage")) 
               System.Windows.Forms.MessageBox.Show(@"Stopped Service!!"); 
              return; 
             } 
            } 

           } 
           finally 
           { 
            service.Close(); 
           } 

          } 

           ServiceBase[] ServicesToRun; 
        ServicesToRun = new ServiceBase[] 
        { 
         new ServiceBase[] ServicesToRun; 
        ServicesToRun = new ServiceBase[] 
        { 
         new PriceCheckerService() 
        }; 
        ServiceBase.Run(ServicesToRun);() 
        }; 
        ServiceBase.Run(ServicesToRun); 

        } 
     } 
+0

Pouvez-vous nous dire en ligne à quelle exception? – Deepak

+0

Formatez votre code, celui-ci ne sera même pas compilé. –

+0

@Deepak lorsque la condition "args. Contains (" -s1 ")" est vraie et dans la ligne "service.start();" –

Répondre

0

Je pensais qu'il y est une erreur, car les fenêtres existent mise à jour ou la mise à jour VS mais ce n'est pas le cas

doese Quelqu'un at-il une solution?