防止 Form1 上的对话框阻止与 Form2 的交互?

Preventing dialog on Form1 from blocking interaction with Form2?

我正在使用具有两种形式的 WinForm 应用程序。第一种形式是具有所有逻辑的主要形式。第二个窗体包含浏览器控件,并根据从 Form1 传递的数据访问内部网页。然后可以与该网页进行交互。当在 Form1 上弹出 MessageBox 时出现问题,交互在 Form2 上被阻止。

有没有办法在回答 MessageBox 之前启用 Form2 的交互?

OpenBrowser(docIDs, txtID.Text)
 Me.Activate()
 resultYESNO = MessageBox.Show(Me, questionText, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
         If resultYESNO = DialogResult.Yes Then
           columnValue = "Y"
          ElseIf resultYESNO = DialogResult.No Then
           columnValue = "N"
           End If

OpenBrowser 子程序:

Private Sub OpenBrowser(ByVal docIDs As List(Of String), ByVal ID As String)
    If Not Application.OpenForms().OfType(Of Browser).Any Then
        Dim browser = New Browser()
    End If
    Dim encodeIDs As String
    encodeIDs = String.Join(",", docIDs.ToArray())
    Dim barray As Byte() = System.Text.Encoding.UTF8.GetBytes(encodeIDs)
    Dim encodedIDs = System.Convert.ToBase64String(barray)
    Dim url = ConfigurationManager.AppSettings("MyBrowserPath")
    Browser.WebBrowser1.Url = New Uri(url & encodedIDs)
    Dim area = Screen.PrimaryScreen.WorkingArea
    Dim width = CInt(area.Width / 2)
    Dim height = CInt(area.Height)
    Browser.Width = width
    Browser.Height = 800
    Browser.SetDesktopLocation(width, 0)
    Browser.Show()
    Browser.BringToFront()
    Browser.Activate()
End Sub

以下示例显示了如何创建不同的 UI 线程并在不同的线程上显示不同的表单。然后模态对话框表单在创建它们的线程中是模态的:

Imports System.Threading
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For i = 1 To 2
            Dim index = i
            Dim t = New Thread(
                Sub()
                    Dim f = New Form With {.Text = $"Form {index}"}
                    Dim b = New Button With {.Text = "Click Me."}
                    AddHandler b.Click,
                        Sub()
                            Using d As New Form()
                                d.StartPosition = FormStartPosition.CenterParent
                                d.Size = New Drawing.Size(100, 100)
                                d.ShowDialog()
                            End Using
                        End Sub
                    f.Controls.Add(b)
                    Application.Run(f)
                End Sub)
            t.SetApartmentState(ApartmentState.STA)
            t.IsBackground=True
            t.Start()
        Next
    End Sub
End Class