小编Nau*_*mar的帖子

UserControl抛出异常"跨线程操作无效"

我有一个usercontrol和两个类,我想将我的class1的结果打印到usercontrol.I我正在使用这一行从类发送结果

((merge.MyControl)(MyControlInstance)).CLIDisplay = e.WorkItem.CustomerId;
Run Code Online (Sandbox Code Playgroud)

我的控件属性显示结果是

public string CLIDisplay
        {
            get { return lblResultCLI.Text; }
            set
            {
                    lblResultCLI.Text = value;

            }
        }
Run Code Online (Sandbox Code Playgroud)

但是当我把一个类调到我的c#表单时,我得到了Exception

An exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll but was not handled in user code

Additional information: Cross-thread operation not valid: Control 'tbxEvents' accessed from a thread other than the thread it was created on.
Run Code Online (Sandbox Code Playgroud)

c# user-controls winforms

1
推荐指数
1
解决办法
6970
查看次数

标签 统计

c# ×1

user-controls ×1

winforms ×1