Creating WPF components in background thread

Posted by mizipzor on Stack Overflow See other posts from Stack Overflow or by mizipzor
Published on 2010-06-10T20:37:50Z Indexed on 2010/06/10 20:43 UTC
Read the original article Hit count: 260

Im working on a reporting system, a series of DocumentPage are to be created through a DocumentPaginator. These documents include a number of WPF components that are to be instantiated so the paginator includes the correct things when later sent to the XpsDocumentWriter (which in turn is sent to the actual printer).

My problem now is that the DocumentPage instances take quite a while to create (enough for Windows to mark the application as frozen) so I tried to create them in a background thread, which is problematic since WPF expects the attributes on them to be set from the GUI thread. I would also like to have a progress bar showing up, indicating how many pages have been created so far. Thus, it looks like Im trying to get two things to happen in parallell on the GUI.

The problem is hard to explain and Im really not sure how to tackle it. In short:

  • Create a series of DocumentPage's.
    • These include WPF components
    • These are to be created on a background thread, or use some other trick so the application isnt frozen.
  • After each page is created, a WPF ProgressBar should be updated.

If there is no decent way to do this, alternate solutions and approaches are more than welcome.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about multithreading