Code snippet
string[] result = new string[50];
int count = 0;
Process[] processes = Process.GetProcesses();
foreach(var process in processes)
{
if (process.MainWindowTitle
.IndexOf("e", StringComparison.InvariantCulture) > -1)
{
result[count] = process.MainWindowTitle;
count++;
}
}
Please review this question (and the accepted answer) that guides my answer.
Edit:
If I understand correctly, you want to retrieve de list of processes main window titles.
Analysing your code below, the toClose
variable always store one title: the proc.MainWindowTitle
value.
string[] toClose = { proc.MainWindowTitle };
You must retrieve each window title using the foreach
statement of my original answer. Then, you must use the result
variable in the proposed solution instead of toClose
variable on your piece of code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…