/// <summary> /// Raises the DoWork event. /// </summary> /// <param name="e">A <see cref="QueuedWorkerDoWorkEventArgs"/> that contains event data.</param> protected virtual void OnDoWork(QueuedWorkerDoWorkEventArgs e) { if (DoWork != null) { DoWork(this, e); } }
/// <summary> /// Handles the DoWork event of the queued background worker. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ImageGlass.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance /// containing the event data.</param> void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e) { string extension = e.Argument as string; // Should we continue processing this item? // The callback checks if the item is already cached. if (!OnCanContinueProcessing(extension)) { e.Cancel = true; return; } // Read shell info ShellInfoExtractor info = ShellInfoExtractor.FromFile(extension); // Return the info CacheItem result = null; if ((info.SmallIcon == null || info.LargeIcon == null) && !RetryOnError) { result = new CacheItem(extension, info.SmallIcon, info.LargeIcon, info.FileType, CacheState.Error); } else { result = new CacheItem(extension, info.SmallIcon, info.LargeIcon, info.FileType, CacheState.Cached); } e.Result = result; }
/// <summary> /// Handles the DoWork event of the queued background worker. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ImageGlass.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance /// containing the event data.</param> void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e) { CacheRequest request = e.Argument as CacheRequest; // Should we continue processing this item? // The callback checks the following and returns false if // the item is already cached -OR- // the item is in the edit cache -OR- // the item is outside the visible area (only if the CacheMode is OnDemand). if (!OnCanContinueProcessing(request)) { e.Cancel = true; return; } Image thumb = null; string diskCacheKey = GetKey(request.Guid, request.Size, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC); // Check the disk cache using (MemoryStream stream = new MemoryStream()) { if (diskCache.Read(diskCacheKey, stream)) { thumb = new Bitmap(stream); } } // Extract the thumbnail from the source image. if (thumb == null) { thumb = request.Adaptor.GetThumbnail(request.VirtualItemKey, request.Size, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC); // Save to disk cache if (thumb != null) { using (MemoryStream stream = new MemoryStream()) { thumb.Save(stream, System.Drawing.Imaging.ImageFormat.Png); diskCache.Write(diskCacheKey, stream); } } } // Return the thumbnail CacheItem result = null; if (thumb == null && !RetryOnError) { result = new CacheItem(request.Guid, request.Size, null, CacheState.Error, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC); } else { result = new CacheItem(request.Guid, request.Size, thumb, CacheState.Cached, request.UseEmbeddedThumbnails, request.AutoRotate, request.UseWIC); } e.Result = result; }
/// <summary> /// Handles the DoWork event of the queued background worker. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ImageGlass.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance /// containing the event data.</param> void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e) { CacheRequest request = e.Argument as CacheRequest; // Should we continue processing this item? // The callback checks the following and returns false if // the item is in the edit cache -OR- // the item was fetched by the UI thread before. if (!OnCanContinueProcessing(request)) { e.Cancel = true; return; } // Get item details e.Result = request.Adaptor.GetDetails(request.VirtualItemKey, request.UseWIC); }
/// <summary> /// [IG_CHANGE] Handles the DoWork event of the queued background worker. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ImageGlass.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance /// containing the event data.</param> void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e) { CacheRequest request = e.Argument as CacheRequest; // Should we continue processing this item? // The callback checks the following and returns false if // the item is in the edit cache -OR- // the item was fetched by the UI thread before. if (!OnCanContinueProcessing(request)) { e.Cancel = true; return; } // Get item details // Note: // If we use WIC, it will cause Memory Leak issue: https://github.com/d2phap/ImageGlass/issues/119 e.Result = request.Adaptor.GetDetails(request.VirtualItemKey, false);// request.UseWIC); }
/// <summary> /// Used by the worker thread to process items. /// </summary> private void Run() { while (!Stopping) { lock (lockObject) { // Wait until we have pending work items if (paused || IsWorkQueueEmpty()) { Monitor.Wait(lockObject); } } // Loop until we exhaust the queue bool queueFull = true; while (queueFull && !Stopping && !Paused) { // Get an item from the queue AsyncOperation asyncOp = null; object request = null; int priority = 0; lock (lockObject) { // Check queues Utility.Tuple <AsyncOperation, int> work = GetWork(); asyncOp = work.Item1; priority = work.Item2; if (asyncOp != null) { request = asyncOp.UserSuppliedState; } // Check if the item was removed if (request != null && cancelledItems.ContainsKey(request)) { request = null; } } if (request != null) { Exception error = null; // Start the work QueuedWorkerDoWorkEventArgs doWorkArg = new QueuedWorkerDoWorkEventArgs(request, priority); try { // Raise the do work event OnDoWork(doWorkArg); } catch (Exception e) { error = e; } // Raise the work complete event QueuedWorkerCompletedEventArgs workCompletedArg = new QueuedWorkerCompletedEventArgs(request, doWorkArg.Result, priority, error, doWorkArg.Cancel); if (!Stopping) { asyncOp.PostOperationCompleted(workCompletedCallback, workCompletedArg); } } else if (asyncOp != null) { asyncOp.OperationCompleted(); } // Check if the cache is exhausted lock (lockObject) { queueFull = !IsWorkQueueEmpty(); } } } }
/// <summary> /// Used by the worker thread to process items. /// </summary> private void Run() { while (!Stopping) { lock (lockObject) { // Wait until we have pending work items if (paused || IsWorkQueueEmpty ()) Monitor.Wait (lockObject); } // Loop until we exhaust the queue bool queueFull = true; while (queueFull && !Stopping && !Paused) { // Get an item from the queue AsyncOperation asyncOp = null; object request = null; int priority = 0; lock (lockObject) { // Check queues Utility.Tuple<AsyncOperation, int> work = GetWork (); asyncOp = work.Item1; priority = work.Item2; if (asyncOp != null) request = asyncOp.UserSuppliedState; // Check if the item was removed if (request != null && cancelledItems.ContainsKey (request)) request = null; } if (request != null) { Exception error = null; // Start the work QueuedWorkerDoWorkEventArgs doWorkArg = new QueuedWorkerDoWorkEventArgs (request, priority); try { // Raise the do work event OnDoWork (doWorkArg); } catch (Exception e) { error = e; } // Raise the work complete event QueuedWorkerCompletedEventArgs workCompletedArg = new QueuedWorkerCompletedEventArgs (request, doWorkArg.Result, priority, error, doWorkArg.Cancel); if (!Stopping) asyncOp.PostOperationCompleted (workCompletedCallback, workCompletedArg); } else if (asyncOp != null) asyncOp.OperationCompleted (); // Check if the cache is exhausted lock (lockObject) { queueFull = !IsWorkQueueEmpty (); } } } }
/// <summary> /// Raises the DoWork event. /// </summary> /// <param name="e">A <see cref="QueuedWorkerDoWorkEventArgs"/> that contains event data.</param> protected virtual void OnDoWork(QueuedWorkerDoWorkEventArgs e) { if (DoWork != null) DoWork (this, e); }
/// <summary> /// Handles the DoWork event of the queued background worker. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ImageGlass.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance /// containing the event data.</param> void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e) { CacheRequest request = e.Argument as CacheRequest; // Should we continue processing this item? // The callback checks the following and returns false if // the item is in the edit cache -OR- // the item was fetched by the UI thread before. if (!OnCanContinueProcessing (request)) { e.Cancel = true; return; } // Get item details e.Result = request.Adaptor.GetDetails (request.VirtualItemKey, request.UseWIC); }
/// <summary> /// Handles the DoWork event of the queued background worker. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ImageGlass.ImageListView.QueuedWorkerDoWorkEventArgs"/> instance /// containing the event data.</param> void bw_DoWork(object sender, QueuedWorkerDoWorkEventArgs e) { string extension = e.Argument as string; // Should we continue processing this item? // The callback checks if the item is already cached. if (!OnCanContinueProcessing (extension)) { e.Cancel = true; return; } // Read shell info ShellInfoExtractor info = ShellInfoExtractor.FromFile (extension); // Return the info CacheItem result = null; if ((info.SmallIcon == null || info.LargeIcon == null) && !RetryOnError) result = new CacheItem (extension, info.SmallIcon, info.LargeIcon, info.FileType, CacheState.Error); else result = new CacheItem (extension, info.SmallIcon, info.LargeIcon, info.FileType, CacheState.Cached); e.Result = result; }