I need to get the text in a RichTextBox while in another thread. I tried invoking like this:
string text = ResultsRTB.Invoke((MethodInvoker)(() => ResultsRTB.Text));
But that obviously doesnt work due to the fact that you can't return anything with MethodInvoker (that I know of). I also tried variations of the suggestions here and here with no luck. I feel like theres an easy way to do this but Im just missing one little thing. Thanks!
You need a delegate type that returns a string. Like Func<string>
:
var text = (string)richTextBox1.Invoke(new Func<string>(() => richTextBox1.Text));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With