Possible to construct form on background thread, then display on UI thread

后端 未结 6 1529
情话喂你
情话喂你 2020-12-10 04:10

UPDATE: Just to summarize what my question has boiled down to:

I was hoping that constructing .NET forms and controls did NOT create any window handles -- hoping tha

6条回答
  •  醉酒成梦
    2020-12-10 04:40

    In general, properties of the form need to be accessed from the same thread running the message loop. That means, in order to construct the form on another thread, you would need to marshal any calls to actually set properties using BeginInvoke. This is true for property sets from the constructor, too, if they end up generating a message that needs to be processed (as is happening to you now).

    Even if you get that to work, what does it buy you? It will be a bit slower, not faster, overall.

    Perhaps just show a splash screen while this form is loading?

    Alternatively, review why your form takes so long to construct in the first place. It's not common for this to take seconds.

提交回复
热议问题