Replies: 4 comments 14 replies
-
Downloading is handled asynchronously, I personally would discourage trying to make it synchronous. You can use the new fluent DownloadHandler implementation to simplify the process. There is also some new method for downloading files given a url. See https://github.com/cefsharp/CefSharp/pull/3576/files#diff-b5d302e3b07bf84e99ffa745fe37affd00a70cae3e5dd66c51911e30540c06c1R342 |
Beta Was this translation helpful? Give feedback.
-
You can use a DispatcherFrame or AutoResetEvent to wait for the download to complete. You would initially need to wait for the OnBeforeDownload event with a timeout, because it may not be raised, if there is an error or the URL is invalid. |
Beta Was this translation helpful? Give feedback.
-
DispatcherFrame is intended to be used in WPF. WinForms doesn't use a dispatcher. @assopri What exactly is your requirement to run your methods sequentially? Something like the following will be much easier to implement and avoids a number of different threading issues. using CefSharp.Fluent;
//Save all files to temp folder, update to whatever suites you.
var userTempPath = System.IO.Path.GetTempPath();
chromiumWebBrowser.DownloadHandler =
DownloadHandler.UseFolder(userTempPath,
(chromiumBrowser, browser, downloadItem, callback) =>
{
if(downloadItem.IsComplete)
{
DoSmthWithDownloadedFile();
}
}); If you can obtain the url you can avoid using a download handler all together and simply directly download the file https://github.com/cefsharp/CefSharp/pull/3576/files#diff-b5d302e3b07bf84e99ffa745fe37affd00a70cae3e5dd66c51911e30540c06c1R342 |
Beta Was this translation helpful? Give feedback.
-
Application.DoEvents() is intended to allow UI refresh. Using it in a loop to wait for another task, you also need to sleep the thread otherwise it will consume 100% processor time. That is why I suggested DispatcherFrame or ResetEvent. I agree that downloading async is best, but that's not the question :-) |
Beta Was this translation helpful? Give feedback.
-
Hello! I`m trying to automate scenario of downloading video from my own youtube channel:
When I click Скачать (Download) in browser the file save dialog appears. I found the solution to use here https://stackoverflow.com/questions/28565319/force-cefsharp-to-download-without-showing-dialog , but its asynchronous. What if I need to wait for download to be finished before getting to next algorithm step? So my canonical code should look like this:
Navigate();
ClickDownloadButton();
WaitForDownloadToFinish();
DoSmthWithDownloadedFile();
How could I organize this?
Beta Was this translation helpful? Give feedback.
All reactions