❔ ✅ Why does this block the UI thread?
I have this function. Calling this seems to be blocking the thread that it's called from.
Did I do something wrong here, or should this not block and maybe something else is causing that?
public async void FindWindowHandle(HandleWindowFind handleWindowFind)
{
if (!started) throw new InvalidOperationException("Process not started");
if (playerWindowHandle != IntPtr.Zero)
{
handleWindowFind(playerWindowHandle);
return;
}
var finding = IntPtr.Zero;
await Task.Run(() =>
{
while (finding == IntPtr.Zero)
{
Thread.Yield();
finding = GetWindow(_hostWindow, 5);
}
});
handleWindowFind(playerWindowHandle = finding);
}