i am created one method which is call be another thread it is windows application
in the form i have one text Box in in the thread method i assign some text to that text box in that point i got an error
that is
error:-
cross thread operation not Valid:control txtLogFile accessed from a thread other than the thread it was created how to resolve this issue...
Loading
Riaan SwartPosted Sep 10, 2010, 6:17 AM
Create a delegate that you can point to the method to invoke it if needed:
private delegate void TextboxString(string TextToDisplay);
Now create the method that you will call from within the thread that should give the textbox the display string:
private void SetTextboxDisplay(string TextToDisplay)
{
if(yourTextboxName.InvokeRequired)
{
TextboxString textboxString = new TextboxString(SetTextboxDisplay);
this.Invoke(textboxString, new object[]{TextToDisplay});
}
else
{
yourTextboxName.Text = TextToDisplay;
}
}
So nou you just call this method within the trhead that must change your textbox text with the parameter of what the text should be
SetTextboxDisplay("The text you want in the textbox");