Our web application generates a lot of images (layered building plans) through low level WPF by non-STAThreads with cached frozen objects, like Geometries, Brushes, DrawingGroups. The rendering process is parallelized trough Tasks. In .NET 4 the ThreadPool regularly terminates Threads without releasing the associated Dispatchers.
The private static WeakReference list _dispatchers in Dispatcher class is steadily growing until exceptions occur upon creating WPF-objects:
Exception type: System.ComponentModel.Win32Exception
Exception message: The operation completed successfully
This occurs inside the Dispatcher -> MS.Win32.HwndWrapper constructor.
With a memory profiler we could find out, that the Dispatcher remains in memory because a reference is hold by a MediaContext object. As soon as e.g. DrawingContext.RenderOpen is called, a MediaContext object is created that will never be released. This results in steady growing memory usage and handles until the error occurs.
A similar error is bug ID 620588.