Пример #1
0
        /// <summary>
        /// Handles the RunWorkerCompleted event of the queued background worker.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Manina.Windows.Forms.QueuedWorkerCompletedEventArgs"/>
        /// instance containing the event data.</param>
        void bw_RunWorkerCompleted(object sender, QueuedWorkerCompletedEventArgs e)
        {
            CacheRequest request = e.UserState as CacheRequest;

            // We are done processing
            processing.Remove(request.Guid);

            // Do not process the result if the cache operation
            // was cancelled.
            if (e.Cancelled)
            {
                return;
            }

            // Get result
            Utility.Tuple <ColumnType, string, object>[] details = (Utility.Tuple <ColumnType, string, object>[])e.Result;
            if (details != null && mImageListView != null)
            {
                mImageListView.UpdateItemDetailsInternal(request.Guid, details);
            }

            // Refresh the control lazily
            if (mImageListView != null && mImageListView.IsItemVisible(request.Guid))
            {
                mImageListView.Refresh(false, true);
            }

            // Raise the CacheError event
            if (e.Error != null && mImageListView != null)
            {
                mImageListView.OnCacheErrorInternal(request.Guid, e.Error, CacheThread.Details);
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the RunWorkerCompleted event of the queued background worker.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Manina.Windows.Forms.QueuedWorkerCompletedEventArgs"/>
        /// instance containing the event data.</param>
        private void bw_RunWorkerCompleted(object sender, QueuedWorkerCompletedEventArgs e)
        {
            CacheItem result = e.Result as CacheItem;

            // We are done processing
            processing.Remove(result.Extension);

            // Add to cache
            if (result != null)
            {
                if (shellCache.TryGetValue(result.Extension, out CacheItem existing))
                {
                    existing.Dispose();
                    shellCache.Remove(result.Extension);
                }
                shellCache.Add(result.Extension, result);
            }

            // Refresh the control lazily
            if (result != null && mImageListView != null)
            {
                mImageListView.Refresh(false, true);
            }

            // Raise the ShellInfoCached event
            if (result != null && mImageListView != null)
            {
                mImageListView.OnShellInfoCached(new ShellInfoCachedEventArgs(result.Extension, result.SmallIcon, result.LargeIcon, result.FileType));
            }

            // Raise the CacheError event
            if (e.Error != null && mImageListView != null)
            {
                mImageListView.OnCacheErrorInternal(e.Error, CacheThread.ShellInfo);
            }
        }
        /// <summary>
        /// Handles the RunWorkerCompleted event of the queued background worker.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ImageGlass.ImageListView.QueuedWorkerCompletedEventArgs"/>
        /// instance containing the event data.</param>
        void bw_RunWorkerCompleted(object sender, QueuedWorkerCompletedEventArgs e)
        {
            CacheRequest request = e.UserState as CacheRequest;
            CacheItem    result  = e.Result as CacheItem;

            // We are done processing
            if (request.RequestType == RequestType.Renderer)
            {
                processingRendererItem = Guid.Empty;
            }
            else if (request.RequestType == RequestType.Gallery)
            {
                processingGalleryItem = Guid.Empty;
            }
            else
            {
                processing.Remove(request.Guid);
            }

            // Do not process the result if the cache operation
            // was cancelled.
            if (e.Cancelled)
            {
                return;
            }

            // Dispose old item and add to cache
            if (request.RequestType == RequestType.Renderer)
            {
                if (rendererItem != null)
                {
                    rendererItem.Dispose();
                }

                rendererItem = result;
            }
            else if (request.RequestType == RequestType.Gallery)
            {
                if (galleryItem != null)
                {
                    galleryItem.Dispose();
                }

                galleryItem = result;
            }
            else if (result != null)
            {
                CacheItem existing = null;
                if (thumbCache.TryGetValue(result.Guid, out existing))
                {
                    existing.Dispose();
                    thumbCache.Remove(result.Guid);
                }
                thumbCache.Add(result.Guid, result);

                if (result.Image != null)
                {
                    // Did the thumbnail size change while we were
                    // creating the thumbnail?
                    if (result.Size != mImageListView.ThumbnailSize)
                    {
                        result.State = CacheState.Unknown;
                    }

                    // Purge invisible items if we exceeded the cache limit
                    MemoryUsed += GetImageMemorySize(result.Image);
                    if (IsCacheLimitExceeded())
                    {
                        PurgeInvisible(true);
                    }
                }
            }

            //Refresh the control
            if (mImageListView != null)
            {
                if (request.RequestType != RequestType.Thumbnail || mImageListView.IsItemVisible(request.Guid))
                {
                    mImageListView.Refresh(false, true);
                }
            }

            // Raise the ThumbnailCached event
            if (mImageListView != null)
            {
                mImageListView.OnThumbnailCachedInternal(result.Guid, result.Image, result.Size, request.RequestType == RequestType.Thumbnail);
            }

            // Raise the CacheError event
            if (e.Error != null && mImageListView != null)
            {
                mImageListView.OnCacheErrorInternal(result.Guid, e.Error, CacheThread.Thumbnail);
            }
        }