protected virtual void KillPlayer()
        {
            Logger.ReportVerbose("Killing {0}", ControllerName);

            string processName = CurrentProcessName;

            if (CurrentProcess != null)
            {
                Logger.ReportVerbose("Killing " + ControllerName);

                try
                {
                    CurrentProcess.Kill();
                }
                catch (Exception ex)
                {
                    Logger.ReportException("Error killing {0}", ex, ControllerName);
                }
            }

            if (!string.IsNullOrEmpty(processName))
            {
                KillProcesses(processName);
            }
        }
예제 #2
0
        /// <summary>
        /// Runs the specified URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <remarks>...</remarks>
        public static void Run(string url = null)
        {
            try {
                if (CurrentProcess != null)
                {
                    if (!CurrentProcess.HasExited)
                    {
                        CurrentProcess.Kill();
                    }
                    CurrentProcess = null;
                }
            }
            catch /* Eat */ { /* Tasty ? */ }

            try {
                var p = new Process();
                if (string.IsNullOrWhiteSpace(url))
                {
                    p.StartInfo.Arguments = string.Format("--data-path=\"{0}\"", Api.CacheRoot);
                }
                else
                {
                    p.StartInfo.Arguments = string.Format("--data-path=\"{0}\" --url=\"{1}\"", Api.CacheRoot, url);
                }
                p.StartInfo.FileName        = Path.Combine(Location, "nw.exe");
                p.StartInfo.UseShellExecute = true;
                p.Start();

                App.Current.ShowNotification(new Notification(Definitions.NWRunHelpTitle, Definitions.NWRunHelpContent));

                CurrentProcess = p;
            }
            catch /* Eat */ { /* Tasty ? */ }
        }
예제 #3
0
        public static void RunGraph(string graph_path, ReadInput input_function)
        {
            if (CurrentProcess != null && !CurrentProcess.HasExited)
            {
                CurrentProcess.Kill();
            }

            CurrentProcess = FetchNewProcess(graph_path);
            Aborting       = false;

            if (input_function != null)
            {
                CurrentProcess.StartInfo.RedirectStandardInput = true;
            }

            try
            {
                //Start process and asynchronous reading
                CurrentProcess.Start();
                CurrentProcess.BeginOutputReadLine();
                CurrentProcess.BeginErrorReadLine();

                if (input_function != null)
                {
                    using (StreamWriter writer = new StreamWriter(CurrentProcess.StandardInput.BaseStream, Encoding.ASCII))
                    {
                        while (!CurrentProcess.HasExited && !Aborting)
                        {
                            byte[] input = input_function();

                            if (input != null && input.Length != 0)
                            {
                                writer.WriteLine(Encoding.ASCII.GetString(input));
                            }
                            else
                            {
                                writer.Flush();
                            }
                        }
                    }
                }

                if (Aborting && !CurrentProcess.HasExited)
                {
                    CurrentProcess.Kill();
                    CurrentProcess.WaitForExit();
                    VSLogger.Log("Aborted current process.");
                }
            }
            catch (Win32Exception exception)
            {
                VSLogger.LogError("Output:\n" + exception.ToString());
            }

            CurrentProcess.WaitForExit();
            CurrentProcess = null;
            Aborting       = false;
        }
예제 #4
0
 public void KillOpenVpn()
 {
     if ((CurrentProcess != null))
     {
         CurrentProcess.Kill();
         CurrentProcess.WaitForExit(1000);
         CurrentProcess = null;
     }
 }
예제 #5
0
 public virtual void Kill()
 {
     if (CurrentProcess != null)
     {
         if (!CurrentProcess.HasExited)
         {
             CurrentProcess.Kill();
         }
     }
 }
        static void Exit(object sender, EventArgs e)
        {
            // We must manually tidy up and remove the icon before we exit.
            // Otherwise it will be left behind until the user mouses over.
            TrayIcon.Visible = false;
            TrayIcon.Dispose();
            CurrentProcess?.Kill();
            ExitApplication.Dispose();

            Application.Exit();
        }
예제 #7
0
 /// <summary>
 /// 杀死进程
 /// </summary>
 /// <param name="processName">进程名</param>
 /// <param name="TimeToKill">延时</param>
 public static void KillProcessAsync(string processName, int TimeToKill)
 {
     if (TimeToKill > 0)
     {
         Thread.Sleep(TimeToKill);
     }
     Process[] Processes = Process.GetProcessesByName(processName);
     foreach (Process CurrentProcess in Processes)
     {
         CurrentProcess.Kill();
     }
 }
예제 #8
0
 private void OnApplicationExit(object sender, ExitEventArgs e)
 {
     CurrentProcess?.Kill();
 }
예제 #9
0
        public bool TryStartApplication(string applicationPath, out string errorText)
        {
            errorText = string.Empty;
            try
            {
                if (CurrentProcess != null && !CurrentProcess.HasExited)
                {
                    CurrentProcess.Kill();
                }

                var startInfo = CreateProcessInfo(applicationPath);

                CurrentProcess = new Process
                {
                    StartInfo           = startInfo,
                    EnableRaisingEvents = true
                };

                CurrentProcess.Exited += OnCurrentProcessExited;
                CurrentProcess.Start();
                CurrentProcess.WaitForInputIdle(30000);

                if (CurrentProcess.HasExited)
                {
                    Process childProcess;

                    // Process terminated before idle state. The reason can be start of another process.
                    if (!TryGetChildProcess(CurrentProcess.Id, out childProcess, out errorText))
                    {
                        return(false);
                    }

                    CurrentProcess = childProcess;
                }

                if (CurrentProcess.MainWindowHandle == IntPtr.Zero)
                {
                    double       timer      = _mainWindowShowTimeout * 1000;
                    const double CheckDelay = 0.100;
                    do
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(CheckDelay));
                        timer -= CheckDelay;
                    } while (timer > 0 && CurrentProcess.MainWindowHandle == IntPtr.Zero);

                    if (CurrentProcess.MainWindowHandle == IntPtr.Zero)
                    {
                        errorText = $"{nameof(Process.MainWindowHandle)} not founded";
                        CurrentProcess.Kill();
                        return(false);
                    }
                }

                AttachToProcess(CurrentProcess);
                OnApplicationStateChanged?.Invoke(this, new ApplicationStateEventArgs(ApplicationState.Started));
                return(true);
            }
            catch (Exception exception)
            {
                errorText = exception.Message;
            }

            return(false);
        }