i've tried to get it working with searching for ProcessName
async Task WaitForBG3()
{
textBox1.Text = "Searching";
await Task.Run(async () =>
{
bool found = false;
while (!found)
{
Process[] ProcessList = Process.GetProcesses();
foreach (Process p in ProcessList)
{
if (p.ProcessName.Contains("bg3"))
{
found = true;
}
}
}
});
textBox1.Text = "found and wait for Exit";
await Task.Run(async () =>
{
bool running = false;
while (!running)
{
Process[] ProcessList = Process.GetProcesses();
foreach (Process p in ProcessList)
{
if (p.ProcessName.Contains("bg3"))
{
running = false;
}
else
{
running = true;
}
}
}
});
textBox1.Text = "Exit";
}
When i test it with Notepad, it's working as it should, but when i use the game name, it's instandly triggering the else part of the 2nd Task. Even when the game is running allready running when calling
private async void buttonStart_Click(object sender, EventArgs e)
{
//LaunchViaSteam();
await WaitForBG3();
//do some mor stuff
}
Any Idea why?