Creating controls in a non-UI thread

前端 未结 3 945
悲哀的现实
悲哀的现实 2020-12-18 03:54

I have a sort of plug-in model in which various complex user controls are stored in DLLs and loaded and instantiated at run time using

Activator.CreateInsta         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-18 04:23

    The code sample in this answer provides an elegant way around this problem.

    Code quoted from that answer:

    public void UpdateTestBox(string newText)
    {
        BeginInvoke((MethodInvoker) delegate {
            tb_output.Text = newText;
        });        
    }
    

    ...although in your case you would want to call BeginInvoke on the controls themselves:

    public void UpdateTestBox(string newText)
    {
        tb_output.BeginInvoke((MethodInvoker) delegate {
            tb_output.Text = newText;
        });        
    }
    

提交回复
热议问题