Problem:
We have a Winforms application that can open another WPF window. This window contains various icons and text and is not too complicated. Returning to the main window, winforms one, it also has a WPF control built in with ElementHost (ElementHost is specifically designed so that Winforms can host WPF Control). However, we noticed that as soon as the memory usage in this application is quite high, this second WPF window can take a considerable amount of time.
We made a small test application in VS2012 that is able to replicate the problem. The test application opens a Winforms window with two buttons; "Add 4gb memory usage" and "Open WPF window". The WPF window has one small icon on it (48 * 48), and thatβs all. When we add 4Gb memory usage and try to open the window for the first time, it takes about 7 seconds to open the window.
CODE: I made the test application and source code publicly available through BitBucket .
What we found out:
- The application certainly works in 64-bit because it will call OutOfMemoryExceptions in 32-bit.
- Without memory, the window opens immediately.
- When using memory, when you open it for the first time, the window will only be slow.
- If the WPF window has no image, it opens immediately.
- Reducing the size of the host element located in the winforms control to say 1 * 1, the window opens immediately. Obviously, this is not a great solution, as it does not show most of our WPF control by this size.
- The size of the ElementHost in our application is about 1000 * 700, but we noticed that when the ElementHost is reduced, the size, so that it takes 10 seconds, until it reaches 350 * 350, after which it suddenly improves to be fast again. This may be computer dependent or possibly a restriction of some kind.
- Removing the image from the wpf window will make it quick again.
- Adding new images as resources and to the WPF window linearly slows down the opening time (for example, 1 image = 7 seconds, 2 images = 14 seconds).
- Experiment so that the image is the same size as it is on, so there shouldn't be any resizing, but that doesn't seem to make any difference.
- Experimented with different types of images .png, .tiff, .ico, but they all seemed slow.
Has anyone else experienced this problem / Any suggestions on what our next step might be?
user3483066 Apr 01 '14 at 0:27 2014-04-01 00:27
source share