Vb.net Can';无法访问已处理的对象

Vb.net Can';无法访问已处理的对象,vb.net,Vb.net,我正在做一个异步子程序来继续监听UDP客户端。收到消息后,我将使用BeginInvoke更新UI线程。但是现在,当我重新打开表单时,我面临一个问题。它将引发异常-无法访问已处置的对象。对象名称:checkInOut。checkInOut是我的表单名 Private Sub checkInOut_Load(sender As Object, e As EventArgs) Handles Me.Load FormSettings() udpClient.BeginR

我正在做一个异步子程序来继续监听UDP客户端。收到消息后,我将使用BeginInvoke更新UI线程。但是现在,当我重新打开表单时,我面临一个问题。它将引发异常-无法访问已处置的对象。对象名称:checkInOut。checkInOut是我的表单名

Private Sub checkInOut_Load(sender As Object, e As EventArgs) Handles Me.Load
        FormSettings()
        udpClient.BeginReceive(AddressOf udpAsyncReceive, Nothing)
End Sub

Private Sub udpAsyncReceive(asyncResult As IAsyncResult)
    Try
        Dim remoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
        Dim receiveBytes As Byte() = udpClient.EndReceive(asyncResult, remoteIpEndPoint)
        Dim receiveMsg As String = Encoding.UTF8.GetString(receiveBytes)
        If Me.IsHandleCreated = False Then
            Me.CreateHandle()
        End If
        '' Pass the string to a method that runs on the UI thread
        Me.BeginInvoke(New Action(Of String)(AddressOf DataReceived), receiveMsg)
        '' Continue receiving
        udpClient.BeginReceive(AddressOf udpAsyncReceive, Nothing)
    Catch ex As Exception
        GeneralHelper.showExceptionErrorMsg(ex)
    End Try
End Sub

Private Sub DataReceived(receiveMsg As String)
    txtReservationID.Text = receiveMsg
End Sub
我正在使用一个菜单条调用openForm()并重新打开表单

Private Sub CheckInOutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CheckInOutToolStripMenuItem.Click
    GeneralHelper.openForm(New checkInOut)
End Sub
openForm子程序

Public Sub openForm(ByVal formName As Form)

    If Form.ActiveForm.MdiChildren.Length > 0 Then
        For Each childForm In Form.ActiveForm.MdiChildren
            childForm.Close()
        Next
    End If

    formName.MdiParent = Form.ActiveForm
    formName.Show()
End Sub

我期待着解决办法。谢谢。

听起来好像您在某个时间点执行了
checkInOut。在某个时间点关闭
,然后在代码中尝试重新打开它

.close
方法关闭表单并将其标记为待处理。如果你想继续使用表单而不是

checkInOut.Close
使用


你能给我们看看你用来重新打开表单的代码吗?
checkInOut.Hide