The Problem:
We have a Winforms application, which can open up another WPF Window. This window contains various icons and text and isnt overly complex. Back to the main window, the winforms one, this also has a WPF control embedded using ElementHost(ElementHost is specifically designed to make it possible for Winforms to host a WPF Control). We have noticed however, that once the memory usage of this application get quite high, this second WPF Window can take a considerable amount of time to open.
We have made a small test application in VS2012 which is able to replicate the problem. The test application opens a Winforms window which has two buttons; "Add 4gb memory usage" and "Open WPF Window". The WPF Window has a single small icon on it(48*48) and that is all. When we add the 4Gb memory usage and attempt to open the window for the first time, it takes around 7 seconds to open the window.
CODE: I have made the test app and source code publicly available through BitBucket.
Things we have found out:
Has anyone else experienced this problem / Any suggestions on what our next step could be?
After some more analysis using a profiler, this article seemed to be the same issue as what I was experiencing.
typeof(BitmapImage).Assembly.GetType("MS.Internal.MemoryPressure")
.GetField("_totalMemory", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, Int64.MinValue / 2);
Not the nicest solution, but it definitely fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With