Closed adanvdo closed 2 years ago
I tried making a couple things async in the RunVideoDataFetch method, but I still experienced a block in the UI. I havent been able to figure out what's causing it. I don't know if it has to do with the progress reporting events or what. Just FYI
I have found the problem. YoutubeDLProcess.cs
executes process.Start()
synchronously on the main thread.
you need to change
if(!process.Start())
to
if(!await Task.Run(() => process.Start()))
With this change the main thread is no longer blocked. Let me know if you want me to open a PR. It's a pretty simple change if you want to do it yourself. @TheMulti0 @alxnull
Hey @adanvdo, thanks for investigating this. Would be happy to accept a PR with the fix you described!
https://github.com/Bluegrams/YoutubeDLSharp/blob/74b79e28a1e3bd1b058991e48d531c64ca36caa7/YoutubeDLSharp/YoutubeDL.cs#L119
I am using your library in a WinForms app. Although I am calling
await ytdl.RunVideoDataFetch(url)
the UI thread is temporarily blocked and the program freezes for a couple seconds.It seems like one or more lines between line 122 and 131 are taking longer than expected and blocking the UI. I did not dig into it much, but this was the only thing I noticed at a glance that could possibly be blocking the thread.
var opts = GetDownloadOptions();
Moving
GetDownloadOptions
to an async Task and awaiting that task for the options may fix the issue.