문제

I Need to close a process containing the word "SoundCloud" I tried this but wont work it does show the messagebox with the full name but won't close the app the error system.indexoutofRangeException

 private void getprocess()
    {
        StringBuilder sb = new StringBuilder();
        richTextBox1.Clear();
        int i = 1;
        foreach (Process p in Process.GetProcesses("."))
        {
            try
            {
                if (p.MainWindowTitle.Length > 0)
                {

                    if (p.MainWindowTitle.Contains("SoundCloud"))
                    {
                        timer1.Stop();
                        timer1.Enabled = false;
                        MessageBox.Show("Close "+p.MainWindowTitle.ToString());
                        Process[] proc =      Process.GetProcessesByName(p.MainWindowTitle.ToString());
                        proc[0].Kill();

                    }
                    richTextBox1.AppendText("\n"+i.ToString()+" ). " + p.MainWindowTitle.ToString());
                    i++;

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
도움이 되었습니까?

해결책

Just omit the GetProcesssByName part and call p.Kill(). This will kill any process with "SoundCloud" in the main window title.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top