How to Create Form from within non gui thread C#

前端 未结 3 1366
礼貌的吻别
礼貌的吻别 2020-12-30 15:08

I have my main GUI from where I start a long running method in a separate thread. Now from within this separate thread I need to create and show a new form. But when I show

3条回答
  •  爱一瞬间的悲伤
    2020-12-30 16:02

    Put the code that creates the new GUI into the main GUI class and then call the main GUI's Invoke method, or raise an event that the main GUI can subscribe to to know when to trigger the new GUI. If you choose the latter, be sure to use InvokeRequired to determine if you can call the method that creates the new GUI directly or if you need to use an Invoke to get back onto the GUI thread to create the new GUI.

提交回复
热议问题