Bloom.HtmlThumbNailer.CreateThumbNail C# (CSharp) Method

CreateThumbNail() private method

Returns true if it make some attempt at an image, false if navigation is currently suppressed.
private CreateThumbNail ( ThumbnailOrder order, Gecko.GeckoWebBrowser browser, Image &thumbnail ) : bool
order ThumbnailOrder
browser Gecko.GeckoWebBrowser
thumbnail Image
return bool
        private bool CreateThumbNail(ThumbnailOrder order, GeckoWebBrowser browser, out Image thumbnail)
        {
            // runs on threadpool thread
            thumbnail = null;
            using (var temp = EnhancedImageServer.MakeSimulatedPageFileInBookFolder(order.Document))
            {
                order.Done = false;
                browser.Tag = order;
                if (!OpenTempFileInBrowser(browser, temp.Key))
                    return false;

                var browserSize = SetWidthAndHeight(browser);
                if (browserSize.Height == 0) //happens when we run into the as-yet-unreproduced-or-fixed bl-254
                    return false; // will try again later

                try
                {
                    Logger.WriteMinorEvent("HtmlThumNailer ({2}): browser.GetBitmap({0},{1})", browserSize.Width,
                        (uint) browserSize.Height,
                        Thread.CurrentThread.ManagedThreadId);
                    //BUG (April 2013) found that the initial call to GetBitMap always had a zero width, leading to an exception which
                    //the user doesn't see and then all is well. So at the moment, we avoid the exception, and just leave with
                    //the placeholder thumbnail.
                    if (browserSize.Width == 0 || browserSize.Height == 0)
                    {
                        var paperSizeName = GetPaperSizeName(order.Document.RawDom);
                        throw new ApplicationException("Problem getting thumbnail browser for document with Paper Size: " + paperSizeName);
                    }
                    using (Image fullsizeImage = CreateImage(browser))
                    {
                        if (_disposed)
                            return false;
                        thumbnail = MakeThumbNail(fullsizeImage, order.Options);
                        return true;
                    }
                }
                catch (Exception error)
                {
                    Logger.WriteEvent("HtmlThumbNailer ({0}) got {1}", Thread.CurrentThread.ManagedThreadId, error.Message);
                    Logger.WriteEvent("Disposing of all browsers in hopes of getting a fresh start on life");
                    foreach (var browserCacheForDifferentPaperSize in _browserCacheForDifferentPaperSizes)
                    {
                        try
                        {
                            Logger.WriteEvent("Disposing of browser {0}", browserCacheForDifferentPaperSize.Key);
                            browserCacheForDifferentPaperSize.Value.Dispose();
                        }
                        catch (Exception e2)
                        {
                            Logger.WriteEvent(
                                "While trying to dispose of thumbnailer browsers as a result of an exception, go another: " + e2.Message);
                        }
                    }
                    _browserCacheForDifferentPaperSizes.Clear();
            #if DEBUG
                    _syncControl.Invoke((Action) (() => Debug.Fail(error.Message)));
            #endif
                }
            }
            return false;
        }