Get textbox value from a different thread
-
Monday, March 05, 2012 4:00 PM
I have tried using Invoke and a delegate, but it isn't returning the proper value...How do you have a delegate return a value when you use invoke?
Thanks.
- Moved by CoolDadTxMVP Monday, March 05, 2012 4:14 PM Winforms related (From:Visual C# General)
All Replies
-
Monday, March 05, 2012 4:08 PMCould you show us your code?
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva -
Monday, March 05, 2012 4:10 PM
Hi,
you can do this by declaring a return type for the delegete. Like this:
delegate string GetText();
then create a method to retrieve textbox text
string GetTextBoxText() { return textBox1.Text; }then call the method using this code from a different thread:
string textBoxText = (string) textBox1.Invoke(new GetText(GetTextBoxText));
Bilhan silva
- Proposed As Answer by Konrad NeitzelMicrosoft Community Contributor Monday, March 05, 2012 4:11 PM
- Marked As Answer by DSabol Monday, March 05, 2012 4:16 PM
-
Monday, March 05, 2012 4:17 PMThank you. That is basically what I was trying to use...but I guess I had somethign wrong, when I retyped it out it worked. Thanks!
-
Monday, March 05, 2012 4:18 PMYou're welcome DSabol.
Bilhan silva
-
Wednesday, March 07, 2012 2:27 AMModerator
I'm glad to hear that the question is solved.
Have a good day!
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us


