Creating controls in a non-UI thread

前端 未结 3 947
悲哀的现实
悲哀的现实 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:42

    Not knowing the details of the InvokeRequired mechanism, I have been experimenting a little and afaik you can set most properties in a Thread as long as it has not been Parented (ie added to some Control.Controls property).

    So you should be able to prepare your controls, store them in a list and attach them to the main UI in an Invoked method.


    Edit: I don't think it matters which Thread created a Control. So the normal rules should apply, ie you can only work with controls form the main Windows thread. And I think the criterion is HandleCreated rather than Parented. As long as that hasn't happened you get a little respite.

提交回复
热议问题