コード例 #1
0
        /// <summary>
        /// The worker process completed, e.g. the command terminated
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.endTime = DateTime.Now;

            bool mustExitApplication = false;

            string message;

            if (e.Error != null)
            {
                message   = "Error running '" + this.command + "': " + e.Error.Message;
                this.Text = "Error '" + this.command + "' - Shell Runner";
            }
            else if (this.commandWasTerminated)
            {
                message   = "Terminated after " + ((TimeSpan)(this.endTime.Subtract(this.startTime))).TotalSeconds.ToString("#,,0") + " seconds.";
                this.Text = "Terminated '" + this.command + "' - Shell Runner";
            }
            else
            {
                message   = "'" + this.command + "' completed in " + ((TimeSpan)(this.endTime.Subtract(this.startTime))).TotalSeconds.ToString("#,,0") + " seconds. Result: " + e.Result.ToString();
                this.Text = "Completed '" + this.command + "' - Shell Runner";

                mustExitApplication = (this.exitIfNoErrors && this.consoleProcess.StandardError.Length == 0);
            }

            this.mainStatusLabel.Text = message;

            this.consoleProcess = null;

            this.startToolStripButton.Enabled    = true;
            this.stopToolStripButton.Enabled     = false;
            this.copyLogToolStripButton.Enabled  = true;
            this.clearLogToolStripButton.Enabled = true;
            this.saveLogToolStripButton.Enabled  = true;

            if (mustExitApplication)
            {
                this.Close();
            }
        }
コード例 #2
0
        /// <summary>
        /// Start the process
        /// </summary>
        private void Start()
        {
            // Set up the console process and events
            this.consoleProcess = new ConsoleProcess();
            this.consoleProcess.OnOutputReceived += new ConsoleProcess.OutputReceivedHandler(ConsoleProcess_OnOutputReceived);
            this.consoleProcess.OnErrorReceived  += new ConsoleProcess.OutputReceivedHandler(ConsoleProcess_OnErrorReceived);

            // Set up the background worker and events
            this.worker                     = new BackgroundWorker();
            this.worker.DoWork             += new DoWorkEventHandler(worker_DoWork);
            this.worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

            // Start the command!
            this.mainStatusLabel.Text = "Running '" + this.command + "'...";
            this.worker.RunWorkerAsync();
            this.startTime = DateTime.Now;
            this.Text      = "Running '" + this.command + "' - Shell Runner";

            this.startToolStripButton.Enabled    = false;
            this.stopToolStripButton.Enabled     = true;
            this.copyLogToolStripButton.Enabled  = false;
            this.clearLogToolStripButton.Enabled = false;
            this.saveLogToolStripButton.Enabled  = false;
        }