C# Get Textbox value in backgroundworker dowork event
backgroundworker, c#, multithreading, thread-safety, winforms
Solution
You can only access `textbox / form controls` in GUI thread, you can do so like that.
if(txtFolderName.InvokeRequired)
{
txtFolderName.Invoke(new MethodInvoker(delegate { name = txtFolderName.text; }));
}
Problem
In my windows forms application I have a `textbox` and `backgroundworker` component. In `dowork` event of the `backgroundworker` I am trying to access value of the textbox. How can i do that? I'm getting following exception in dowork event handler code when I try to access value of the textbox: ``` Cross-thread operation not valid: Control 'txtFolderName' accessed from a thread other than the thread it was created on` ```