c# - Create paragraph in subthread to FlowDocument in main thread -


i´m creating thread long run process , building paragraph shall show in richtextbox.

normally done by:

paragraph paragraph = new paragraph(); paragraph.inlines.add(new textblock() {     text = "hello i´m som text",         textwrapping = textwrapping.nowrap }); richtextbox.document = new flowdocument(paragraph); 

(works fine)

but want paragraph created in thread , added richtextbox like:

thread t = new thread(new threadstart(createtext)); t.start();  private void createtext() {     paragraph paragraph = new paragraph();     paragraph.inlines.add(new textblock()     {         text = "hello i´m som text",             textwrapping = textwrapping.nowrap     });     main.dispatcher.invoke(system.windows.threading.dispatcherpriority.normal, new action(() =>     {         richtextbox.document = new flowdocument(paragraph);     } } 

my problem return error:

the calling thread cannot access object because different thread owns it. on richtextbox.document = new flowdocument(paragraph);

i shared solution problem answer similar question, please refer so answer , my blog post. in terms of performance , lack of ui blocking if should fit needs. if have found way of solving problem since 2013, can share?


Comments