コード例 #1
0
    public MainUIThreadForm()
    {
        Text = "First UI";
        Button button;

        Controls.Add(button = new Button {
            Text = "Start second UI thread", AutoSize = true, Location = new Point(10, 10)
        });
        button.Click += (s, e) =>
        {
            if (secondThreadForm == null || !secondThreadForm.IsHandleCreated)
            {
                secondThreadForm = SecondUIThreadForm.Create();
            }
        };
        Controls.Add(button = new Button {
            Text = "Stop second UI thread", AutoSize = true, Location = new Point(10, 40)
        });
        button.Click += (s, e) =>
        {
            if (secondThreadForm != null && secondThreadForm.IsHandleCreated)
            {
                secondThreadForm.Invoke((Action)(() => secondThreadForm.Close()));
            }
        };
    }
コード例 #2
0
    public MainUIThreadForm()
    {
        Text = "First UI";
        Button button;

        Controls.Add(button = new Button {
            Text = "Start second UI thread", AutoSize = true, Location = new Point(10, 10)
        });
        button.Click += (s, e) =>
        {
            if (secondThreadFormHandle == IntPtr.Zero)
            {
                Form second = SecondUIThreadForm.Create();
                second.HandleCreated   += SecondFormHandleCreated;
                second.HandleDestroyed += SecondFormHandleDestroyed;
            }
        };
        Controls.Add(button = new Button {
            Text = "Stop second UI thread", AutoSize = true, Location = new Point(10, 40)
        });
        button.Click += (s, e) =>
        {
            if (secondThreadFormHandle != IntPtr.Zero)
            {
                PostMessage(secondThreadFormHandle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
            }
        };
    }
コード例 #3
0
    public static SecondUIThreadForm Create()
    {
        SecondUIThreadForm form = new SecondUIThreadForm();

        thread = new Thread(Main2);
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start(form);
        return(form);
    }