use*_*944 4 c# multithreading backgroundworker thread-safety winforms
在我的Windows窗体应用程序中,我有一个textbox
和backgroundworker
组件.在dowork
的情况下,backgroundworker
我试图访问文本框的值.我怎样才能做到这一点?当我尝试访问文本框的值时,我在dowork事件处理程序代码中遇到异常:
Cross-thread operation not valid: Control 'txtFolderName' accessed from a thread other than the thread it was created on`
Run Code Online (Sandbox Code Playgroud)
你只能textbox / form controls
在GUI线程中访问,你可以这样做.
if(txtFolderName.InvokeRequired)
{
txtFolderName.Invoke(new MethodInvoker(delegate { name = txtFolderName.text; }));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11717 次 |
最近记录: |