/// <summary> /// Occurs when the ASP.NET event handler finishes execution. /// </summary> /// <param name="sender"> /// The source of the event. /// </param> /// <param name="e"> /// An <see cref="T:System.EventArgs">EventArgs</see> that contains the event data. /// </param> /// <returns> /// The <see cref="T:System.Threading.Tasks.Task"/>. /// </returns> private Task PostProcessImage(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender).Context; object cachedPathObject = context.Items[CachedPathKey]; if (cachedPathObject != null) { string cachedPath = cachedPathObject.ToString(); // Trim the cache. DiskCache.TrimCachedFolders(cachedPath); // Fire the post processing event. EventHandler <PostProcessingEventArgs> handler = OnPostProcessing; if (handler != null) { context.Items[CachedPathKey] = null; return(Task.Run(() => handler(this, new PostProcessingEventArgs { CachedImagePath = cachedPath }))); } } return(Task.FromResult <object>(null)); }