Sorry for the incomplete answer, which would require me to do some extra research and development, but I would be not enough enthusiastic with your approach to do that. I'm not sure you need to do something special about it. I'll try to explain.
You cannot share the UI object between threads. Isn't that obvious why? You can delegate the method adding the object to UI thread using
Dispatcher.BeginInvoke
, but it will increase the event queue of the thread, so it can defeat the purpose of your improvement.
You need to understand what throughput you are trying to improve. If you have an extra CPU core to handle your processing in parallel utilized more hardware resource, you can really improve the total throughput. This is not always the case: the extra cores might be absent or busy with other processes. You can even increase the total initialization time, due to some overhead of threading and async/await mechanism. What you really want is different: trying to initialize the UI
to the point when it becomes responsive and show the visible part of the window's view in all detail and then complete further rendering in parallel, when the user cares about performance less then about waiting for primary part of UI initialization.
Note that
WPF rendering is already parallelized. This is done through having separate UI thread (this is the thread where
Application.Run
is called) and another one,
rendering thread. So, first of all, you need to clearly understand the
threading model:
http://msdn.microsoft.com/en-us/library/ms741870%28v=vs.110%29.aspx[
^].
You can clearly see the effect of rendering in a separate thread if you write such a simple application as a basic text editor. On initialization, process command-line parameters and load a big file in the editor window (you can do it in the handle of the event
Window.ContentRendered
or overridden method
Window.OnContentRendered
, to see the effect of rendering when everything except the file buffer content is rendered). Probably, just few megabytes would be enough. You will see that you can access the top scroll page of the document much earlier than you can get to the very last page. This is the best you can achieve with your images.
See also these articles:
http://msdn.microsoft.com/en-us/magazine/cc163328.aspx[
^],
http://mrpfister.com/journal/improving-wpf-rendering-performance[
^].
—SA