I’m resizing images using WPF inside the context of an ASP.Net process, and I find that after I put a massive amount of load onto my resizing process, I end up getting the exception “Operation completed successfully”, and my image transformation fails.
Share
This was caused by WPF requiring to run in the context of a HWND (window handle). If WPF operations are run outside the context of a window or application, it will create a new
Dispatcherand consume a window handle in the process. These handles aren’t neccesarily collected at the same time that the .net GC runs, so this leads to a leak.The solution to this is the take a reference to a single dispatcher, e.g.
Dispatcher.CurrentDispatcher, and pass that around to all the methods that need to run WPF operations. The dispatcher can then accept an Action to run, so you can call it with something like_dispatcher.Invoke(() => ClassResizeMethod(image, size))