Bloom.HtmlThumbNailer.ProcessOrder C# (CSharp) Method

ProcessOrder() private method

private ProcessOrder ( object stateInfo ) : void
stateInfo object
return void
        private void ProcessOrder(object stateInfo)
        {
            // called on threadpool thread
            var order = stateInfo as ThumbnailOrder;
            if (order == null)
                return;

            if (Program.ApplicationExiting)
                return;

            Image pendingThumbnail = null;

            lock (this)
            {
                Logger.WriteMinorEvent("HtmlThumbNailer ({1}): starting work on thumbnail ({0})", order.ThumbNailFilePath,
                    Thread.CurrentThread.ManagedThreadId);

                _backgroundColorOfResult = order.Options.BackgroundColor;
                XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(order.Document.RawDom);

                var browser = GetBrowserForPaperSize(order.Document.RawDom);
                if (browser == null)
                    return;

                if (!CreateThumbNail(order, browser, out pendingThumbnail))
                {
                    // For some reason...possibly another navigation was in progress...we can't do this just now.
                    // Try it again later.
                    // Enhance: should we have some limit after which we give up?
                    QueueOrder(order);
                }
                if (pendingThumbnail == null)
                {
                    pendingThumbnail = Resources.PagePlaceHolder;
                }
                else if (!string.IsNullOrEmpty(order.ThumbNailFilePath))
                {
                    try
                    {
                        //gives a blank         _pendingThumbnail.Save(thumbNailFilePath);
                        using (Bitmap b = new Bitmap(pendingThumbnail))
                        {
                            SIL.IO.RobustIO.SaveImage(b, order.ThumbNailFilePath);
                        }
                    }
                    catch (Exception)
                    {
                        //this is going to fail if we don't have write permission
                    }
                }

                pendingThumbnail.Tag = order.ThumbNailFilePath; //usefull if we later know we need to clear out that file

                Debug.WriteLine("Thumbnail created with dimensions ({0},{1})", browser.Width, browser.Height);

                try
                //I saw a case where this threw saying that the key was already in there, even though back at the beginning of this function, it wasn't.
                {
                    if (_images.ContainsKey(order.Key))
                        _images.Remove(order.Key);
                    _images.Add(order.Key, pendingThumbnail);
                }
                catch (Exception error)
                {
                    Logger.WriteMinorEvent("Skipping minor error: " + error.Message);
                    //not worth crashing over, at this point in Bloom's life, since it's just a cache. But since then, I did add a lock() around all this.
                }
            }

            //order.ResultingThumbnail = pendingThumbnail;
            if (_disposed)
                return;
            Logger.WriteMinorEvent("HtmlThumNailer ({1}): finished work on thumbnail ({0})", order.ThumbNailFilePath,
                Thread.CurrentThread.ManagedThreadId);
            order.Callback(pendingThumbnail);
        }