Skip to content

Commit

Permalink
Wait for window handle
Browse files Browse the repository at this point in the history
  • Loading branch information
budcribar committed Dec 29, 2023
1 parent 72807dc commit 6949e8f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion testassets/NUnitTestProject/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;

namespace WebdriverTestProject
{
Expand Down Expand Up @@ -188,13 +189,30 @@ public static Process StartProcess(string executable, string directory)
p.StartInfo.WorkingDirectory = directory;
p.Start();


// Try to prevent COMException 0x8007139F
while (p.MainWindowHandle == IntPtr.Zero)
{
// Refresh process property values
p.Refresh();

// Wait a bit before checking again
Thread.Sleep(100);
}

Console.WriteLine($"Clients started in {sw.Elapsed}");

return p;
}

public static int Count(string name) => Process.GetProcesses().Where(p => p.ProcessName == name).Count();
public static void Kill(string name) => Process.GetProcesses().Where(p => p.ProcessName == name).ToList().ForEach(x => x.Kill());
public static void Kill(string name) => Process.GetProcesses().Where(p => p.ProcessName == name).ToList().ForEach(x =>
{
x.Kill();
// Wait for exit before re-starting
x.WaitForExit();
});

#endregion
}
}

0 comments on commit 6949e8f

Please sign in to comment.