2

here is my code:

[STAThread]
    public static void Main()
    {
        Process[] localByName = Process.GetProcessesByName("faceme");
        Process currentProcess = Process.GetCurrentProcess();
        int nProcessID = Process.GetCurrentProcess().Id;

        var runningProcess = (from process in Process.GetProcesses()
                              where
                                process.Id != currentProcess.Id &&
                                process.ProcessName.Equals(
                                  currentProcess.ProcessName,
                                  StringComparison.Ordinal)
                              select process).FirstOrDefault();

            if (runningProcess != null)
            {
                runningProcess.Kill();
            }

        MyApp.App app = new MyApp.App();
        app.InitializeComponent();
        app.Run();
    }

i got this error when i call runningProcess.Kill() method

varotariya vajsi
  • 3,965
  • 37
  • 39
  • You can find some background reasons here https://stackoverflow.com/questions/49988/really-killing-a-process-in-windows – Steve Jan 01 '18 at 13:24
  • Just fix the bug in this code. Iterate the `localByName` array instead of Process.GetProcesses(). – Hans Passant Jan 01 '18 at 17:58

0 Answers0