Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

UI update problem

$
0
0

Hi, everyone!

I have a to fill heavy data form. It's take a while and I decide to speedup this process by separating in different threads. They start simultaneously and I have to wait till all of them are ended before continue. So, I choose tasks like the kind of threads.

During each task I have to process some data and then fill the part of the data form. To do so, I'm using dispatcher like below:

Me.Dispatcher.BeginInvoke(7, DirectCast(Sub()
     Label1.Content = "Some text"
     End Sub, NoArgDelegate))

It's work just fine. But some data won't work like this and threw an exception: The calling thread cannot access this object because a different thread owns it.

How it's come?

I have a RichTextBox element on my form and use a function to generate FlowDocument. This function work in the new thread. Then, as soon as it ready, I assign value to interface element and catch this exception.

Dim TempDoc As New FlowDocument
TempDoc = FlowD("TextToProcess")
Me.Dispatcher.BeginInvoke(7, DirectCast(Sub()
  MyRichTextBox.Document = TempDoc
  End Sub, NoArgDelegate))

But if I assign straight like bellow (which is meaningless, because it's take some time I want to save), no exception happens.

 Me.Dispatcher.BeginInvoke(7, DirectCast(Sub()
  MyRichTextBox.Document =  FlowD("TextToProcess")
  End Sub, NoArgDelegate))

Any ideas why it's so and how to solve this problem? Thanks.



Aleksey


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>