I have the need to generate dynamically generate a `FlowDocument` from a large set of data. Because the process takes several minutes, I'd like to perform the operation on a background thread rather than have the UI hang.

However, I can't generate the `FlowDocument` on a non-UI thread otherwise attempts to insert rectangles and images cause run-time errors complaining that it's not STA thread.

There are a couple of threads on StackOverflow which seem to involve the same problem I'm having:

* [Accessing a WPF FlowDocument in a BackGround Process](https://stackoverflow.com/questions/6078187/accessing-a-wpf-flowdocument-in-a-background-process)
* [WPF : Is it impossible to UI load in background thread?](https://stackoverflow.com/questions/6977712/wpf-is-it-impossible-to-ui-load-in-background-thread)

In the first link someone suggests the following:

> 
> *"What I'd do: use a `XamlWriter` and serialize the `FlowDocument` into an `XDocument`. The serialization task involves the `Dispatcher`, but once it's done, you can run as many wacky parallel analyses of the data as you want and nothing in the UI will affect it. (Also once it's an `XDocument` you query it with `XPath`, which is a pretty good hammer, so long as your problems are actually nails.)"*
> 
> 
> 

Can someone elaborate on what does the author mean by this?