Bloom.HtmlThumbNailer.SetWidthAndHeight C# (CSharp) Method

SetWidthAndHeight() private method

private SetWidthAndHeight ( Gecko.GeckoWebBrowser browser ) : Size
browser Gecko.GeckoWebBrowser
return System.Drawing.Size
        private Size SetWidthAndHeight(GeckoWebBrowser browser)
        {
            try
            {
                if (_syncControl.InvokeRequired)
                {
                    return (Size) _syncControl.Invoke(new Func<GeckoWebBrowser, Size>(SetWidthAndHeight), browser);
                }
            }
            catch (Exception e)
            {
                NonFatalProblem.Report(ModalIf.None, PassiveIf.Alpha, "Could not make thumbnail","Ref bl-524", e);
                return new Size(0,0); // this tells the caller we failed
            }

            Guard.AgainstNull(browser.Document.ActiveElement, "browser.Document.ActiveElement");
            var div = browser.Document.ActiveElement.EvaluateXPath("//div[contains(@class, 'bloom-page')]").GetNodes().FirstOrDefault() as GeckoElement;
                        if (div == null)
                        {
                var order = (ThumbnailOrder)browser.Tag;
                Logger.WriteEvent("HtmlThumNailer ({1}):  found no div with a class of bloom-Page ({0})", order.ThumbNailFilePath,
                    Thread.CurrentThread.ManagedThreadId);
                            throw new ApplicationException("thumbnails found no div with a class of bloom-Page");
                        }
                        browser.Height = div.ClientHeight;
                        browser.Width = div.ClientWidth;
            // This is probably not needed...width zero came about in debugging incomplete code where a stylesheet
            // did not take effect..but it seems like a reasonable bit of defensive programming to keep.
            if (browser.Width == 0)
                browser.Width = browser.Height/2; // arbitrary way of avoiding crash
            return new Size(browser.Width, browser.Height);
        }