Jason94
Jason94

Reputation: 13620

How can I get a TextBox text in another thread?

I'm doing all crazy stuff today :D I tried invoking it by

Dispatcher.BeginInvoke(() =>
                {
                    username = UsernameInput.Text;
                });

But that does not seem to work :( And how do I also set a value cross thread?

Upvotes: 0

Views: 393

Answers (2)

Jason94
Jason94

Reputation: 13620

Problem solved by sleeping the thread for a second after Dispather. Guess you have to allow the gui thread to "answer" the other thread.

Upvotes: 0

Yuki Kutsuya
Yuki Kutsuya

Reputation: 4098

I did this some time ago, don't know if it's the right way to do it but it works tho:

Invoke((MethodInvoker)delegate
{
    // Code...
});

Upvotes: 1

Related Questions