When executing this code
Paragraph par =new Paragraph(); par.Inlines.Add(msgToSend.strMessage); ChatBox.Document.Blocks.Add(par);
An exception is thrown "how can you solve this problem?"
Perhaps not the best way, but in my case it works. Used form.invoke. The progress bar was made, which was updated in the window, depending on the calculations in another thread. So, the code in the main window of type ImageConverterForm: Form with progress bar
public void ProgressHandler(int p) { if (progressBar.Value < progressBar.Maximum) { progressBar.Value += p; } }
Call code for changing property value
MainForm.Invoke(new ThreadStart(delegate { MainForm.ProgressHandler(1); }));
Update: for the WPF application, nothing has changed except for invoking. New form
MainForm.Dispatcher.Invoke(new ThreadStart(delegate { MainForm.ProgressHandler(1); }));
where MainForm is a form of InvokeMainWindow: Window
BeginInvoke
better in your case. And new ThreadStart
is superfluous. - VladDThreadStart
has certain semantics - this is the delegate used to start a new thread. I usually write this: Dispatcher.BeginInvoke ((Action) (() => MainForm.ProgressHandler (1))); that is, I use a more neutral Action
. - VladDSource: https://ru.stackoverflow.com/questions/200724/
All Articles
invoke
. - KoVadim