private bool TryKillClient(int attempt = 0)
        {
            const int MAX_ATTEMPTS = 5;

            if (attempt == MAX_ATTEMPTS)
            {
                logger.Error($"Failed to kill client process within {MAX_ATTEMPTS} attempts!");

                return(false);
            }

            logger.Info($"Killing client process with ID = {ClientProcess.Id}.");
            ClientProcess.Kill();

            if (ClientProcess.HasTerminated)
            {
                logger.Info("Client process has terminated.");

                return(true);
            }
            else
            {
                logger.Warn("Failed to kill client process. Trying again...");

                return(TryKillClient(++attempt));
            }
        }
Beispiel #2
0
 /// <summary>
 /// Tries to terminate all running client processes because otherwise the
 /// client executable cannot be replaced by a newer version.
 /// </summary>
 private void StopClientProcesses()
 {
     try
     {
         Process [] ClientProcesses = Process.GetProcessesByName("CrawlWave.Client");
         if (ClientProcesses.Length == 0)
         {
             //there are no client processes running
             return;
         }
         else                 //try to terminate each process
         {
             foreach (Process ClientProcess in ClientProcesses)
             {
                 try
                 {
                     //First try to terminate it by closing its main window.
                     ClientProcess.CloseMainWindow();
                     if (ClientProcess.HasExited)
                     {
                         //attempt to terminate the gui was successful
                         ClientProcess.Close();
                     }
                     else
                     {
                         //The Client is running in quiet mode, so we must kill it
                         //TODO: Use the remoting interface of the Client in order
                         //to stop it and then terminate its process.
                         ClientProcess.Kill();
                     }
                 }
                 catch (Exception e)
                 {
                     if (globals.Settings.LogLevel <= CWLogLevel.LogWarning)
                     {
                         globals.SystemLog.LogWarning("CrawlWave.Client Scheduler failed to terminate all the client processes: " + e.ToString());
                     }
                     continue;                             //try to terminate the rest of the processes.
                 }
             }
         }
     }
     catch (Exception e)
     {
         if (globals.Settings.LogLevel <= CWLogLevel.LogWarning)
         {
             globals.SystemLog.LogWarning("CrawlWave.Client Scheduler encountered an error while stoping the client processes:" + e.ToString());
         }
     }
 }