Get textbox value from a different thread

Answered 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 PM
     
     
    Could you show us your code?

    Marco Minerva [MCPD]
    Blog: http://blogs.ugidotnet.org/marcom
    Twitter: @marcominerva

  • Monday, March 05, 2012 4:10 PM
     
     Answered Has Code

    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

  • Monday, March 05, 2012 4:17 PM
     
     
    Thank 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 PM
     
     
    You're welcome DSabol.

    Bilhan silva

  • Wednesday, March 07, 2012 2:27 AM
    Moderator
     
     

    I'm glad to hear that the question is solved. 

    Have a good day!


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us