private bool OpenTempFileInBrowser(GeckoWebBrowser browser, string filePath)
{
var order = (ThumbnailOrder) browser.Tag;
bool navigationHappened = true;
if (_syncControl.InvokeRequired)
{
using (var waitHandle = new AutoResetEvent(false))
{
order.WaitHandle = waitHandle;
_syncControl.BeginInvoke(new Action<string>(path =>
{
if (!_isolator.NavigateIfIdle(browser, path))
navigationHappened = false; // some browser is busy, try again later.
}), filePath);
waitHandle.WaitOne(10000);
}
if (_disposed || !navigationHappened)
return false;
if (!order.Done)
{
Logger.WriteEvent("HtmlThumbNailer ({1}): Timed out on ({0})", order.ThumbNailFilePath,
Thread.CurrentThread.ManagedThreadId);
#if DEBUG
if (!_thumbnailTimeoutAlreadyDisplayed)
{
_thumbnailTimeoutAlreadyDisplayed = true;
_syncControl.Invoke((Action) (() => Debug.Fail("(debug only) Make thumbnail timed out (won't show again)")));
}
#endif
return false;
}
}
else
{
_isolator.Navigate(browser, filePath); // main thread, not async, we really need it now.
while (!order.Done)
{
Application.DoEvents();
Application.RaiseIdle(new EventArgs()); // needed on Linux to avoid deadlock starving browser navigation
}
}
return true;
}