Share via


how to invoked a textbox from another thread ?

Question

Saturday, February 23, 2008 4:08 PM

hello
how do i invoke a textbox from another thread ?

how do i create a thread with parameters.

All replies (3)

Saturday, February 23, 2008 5:34 PM âś…Answered

Hi,

  what do you want to do with the textbox, just change its content?  You just need to call the Invoke method on the textbox:

 

string newValue = "hi there";

if (textBox.InvokeRequired)

{

    textBox.Invoke((MethodInvoker)delegate { textBox.Text = newValue; });

}

else

{

    textBox.Text = newValue;

}

 

If you want to create a parameterized thread then you can use a ParameterizedThreadStart delegate i.e.

 

Thread t = new Thread(new ParameterizedThreadStart(DoSomething));

t.Start("some string");

 

 

private void DoSomething(object data)

{

    string s = data as string;

 

}


Saturday, February 23, 2008 6:13 PM

 

hello..

i think this is the one i want. will let you know the result 36 hrs later..


Monday, February 25, 2008 12:36 AM

hello..

it does works..

thanks a lot.