Running a windows form in a separate thread

前端 未结 4 1437
孤独总比滥情好
孤独总比滥情好 2021-01-15 02:10

I am dealing with running a control in a form, however the form itself is of no value to me. I essentially want the form to run a task and return a value, however for that I

4条回答
  •  忘掉有多难
    2021-01-15 02:54

    I did this once for my project

    var frmNewForm = new Form1();
    var newThread = new System.Threading.Thread(frmNewFormThread);
    
    newThread.SetApartmentState(System.Threading.ApartmentState.STA);
    newThread.Start();
    

    And add the following Method. Your newThread.Start will call this method.

    public void frmNewFormThread()
    {
        Application.Run(frmNewForm);
    }
    

提交回复
热议问题