The error is:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Cross-thread operation not valid: Control 'richTextBox1' accessed from a thread other than the thread it was created on.
Here is the code:
The richTextBox1.AppendText is where the error is generated.
What's the right way to handle that? I have played around with some BackgroundWorker/RunWorkerAsync examples I found on Google (I think the answer might be somewhere in that approach) but I am not sure how to connect this handler triggered code above to something that's allowed to update the richtextbox.
The example that I got the above code from was using the console to write results, I want to learn how to send those results to a richtextbox.
Using .NET 4.7.2
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Cross-thread operation not valid: Control 'richTextBox1' accessed from a thread other than the thread it was created on.
Here is the code:
C#:
public Form1()
{
InitializeComponent();
string api_key = "#######";
BlurbProvider provider = BlurbProvider.XYZ;
RealTimeClient client = new RealTimeClient(provider, api_key: api_key);
BlurbHandler handler = new BlurbHandler();
client.RegisterBlurbHandler(handler);
client.Join(new string[] { "ABC" });
client.Connect();
handler.OnBlurb += (IBlurb blurb) =>
{
// Console.WriteLine(blurb);
richTextBox1.AppendText(Convert.ToString(blurb));
};
}
What's the right way to handle that? I have played around with some BackgroundWorker/RunWorkerAsync examples I found on Google (I think the answer might be somewhere in that approach) but I am not sure how to connect this handler triggered code above to something that's allowed to update the richtextbox.
The example that I got the above code from was using the console to write results, I want to learn how to send those results to a richtextbox.
Using .NET 4.7.2