private void Work(object sender, DoWorkEventArgs e)
        {
            this.BeginInvoke(new MethodInvoker(() => {
                DisableUI();
                if (ActiveOutput != null)
                {
                    ActiveOutput.Enabled = true;
                }
            }));
            ActivityArguments arguments = (ActivityArguments)e.Argument;

            this.BeginInvoke(new MethodInvoker(() => {
                ActiveOutput.Clear();
                string s = "Current working directory is " + Directory.GetCurrentDirectory() + "." + Environment.NewLine;
                ActiveOutput.AppendText(s);
            }));

            /*
             * string executable = NUIXWORKSTATIONDIRECTORY;
             * if (arguments.Type == "java")
             * {
             *  executable = executable + "\\jre\\bin\\java.exe";
             * }
             * else
             * {
             *  executable = executable + "\\nuix_console.exe";
             * }
             */
            using (Process process = new Process())
            {
                //this.BeginInvoke(new MethodInvoker(() => { ActiveOutput.AppendText("Preparing to invoke " + "\"" + arguments.FileName + "\" " + arguments.Arguments + Environment.NewLine); }));
                process.StartInfo.FileName               = "\"" + arguments.FileName + "\"";
                process.StartInfo.Arguments              = arguments.Arguments;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.OutputDataReceived              += Redirect;
                process.ErrorDataReceived += Redirect;
                process.Start();
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
                process.WaitForExit();
            }
        }
        public void StartActivity(string FileName, String Arguments, RichTextBox Output)
        {
            ActivityArguments arguments = new ActivityArguments();

            arguments.FileName  = FileName;
            arguments.Arguments = Arguments;
            ActiveOutput        = Output;
            using (BackgroundWorker worker = new BackgroundWorker())
            {
                worker.DoWork             += new DoWorkEventHandler(Work);
                worker.ProgressChanged    += new ProgressChangedEventHandler(Progress);
                worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Done);
                if (!worker.IsBusy)
                {
                    worker.RunWorkerAsync(arguments);
                }
            }
        }
 public void StartActivity(string FileName, String Arguments, RichTextBox Output)
 {
     ActivityArguments arguments = new ActivityArguments();
     arguments.FileName = FileName;
     arguments.Arguments = Arguments;
     ActiveOutput = Output;
     using (BackgroundWorker worker = new BackgroundWorker())
     {
         worker.DoWork += new DoWorkEventHandler(Work);
         worker.ProgressChanged += new ProgressChangedEventHandler(Progress);
         worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Done);
         if (!worker.IsBusy)
         {
             worker.RunWorkerAsync(arguments);
         }
     }
 }