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:
In the first link someone suggests the following:
"What I'd do: use a
XamlWriter
and serialize theFlowDocument
into anXDocument
. The serialization task involves theDispatcher
, 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 anXDocument
you query it withXPath
, 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?