Form.Owner installs from a separate thread in .NET 3.5

I am writing a test application where I need to put the form in a separate stream.

So, if I create a form window from the main thread and set it to .Owner = it all works. If I create a UIThread thread and install Owner from a new thread, I get an exception. Getting exceptions is understandable, since you cannot access forms directly. My question is, is there a message that I need to catch in the main thread and make BeginInvoke to push the pump message on it? Since UIForm ShowInTaskbar is set to false, I need to click the main application on the taskbar and restore all its child windows.

private void UIThread() // New Thread call
{
        UIForm form = new UIForm();

        form.ShowInTaskbar = false;
        form.Owner = this;

        Application.Run(form); // Expected Exception
}
+3
source share
1 answer

, , Application.Run . , .

Application.Run(new Form1());
-----------------
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        var thread = new Thread(
            () =>
                {
                    var form2 = new Form {Owner = this};
                });
        thread.Start();
    }
}
0

Source: https://habr.com/ru/post/1795613/


All Articles