Passing info from a thread
-
I'm running a process in a thread and want to put the results as they happen in a text box on my form. Is that possible? I cant seem to make it work.
It's possible, you just have to transfer the results to the UI thread before updating the text box. 2 common ways of doing this:
// on the background thread
textBox.Invoke((MethodInvoker)delegate()
{
textBox.Text = "here are the results...";
});The other common way and recommended way is to use a BackgroundWorker[^] component. It lets you run work on a background thread and call worker.ReportProgress, which fires an event on the proper thread, allowing you to update your UI in there.
Life, family, faith: Give me a visit. From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of." Judah Himango
-
It's possible, you just have to transfer the results to the UI thread before updating the text box. 2 common ways of doing this:
// on the background thread
textBox.Invoke((MethodInvoker)delegate()
{
textBox.Text = "here are the results...";
});The other common way and recommended way is to use a BackgroundWorker[^] component. It lets you run work on a background thread and call worker.ReportProgress, which fires an event on the proper thread, allowing you to update your UI in there.
Life, family, faith: Give me a visit. From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of." Judah Himango
I don't believe the cast to MethodInvoker is necessary.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway -
I don't believe the cast to MethodInvoker is necessary.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest HemingwayIt is because the parameter type is Delegate. The compiler cannot infer which delegate type you mean when passing in an anonymous method; you'll get a "cannot convert anonymous method to type System.Delegate because it is not a delegate type" compiler error.
Life, family, faith: Give me a visit. From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of." Judah Himango