0
我正在做一个异步子例程来继续监听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
我很期待的解决方案。谢谢。
你能告诉我们你的代码使用重新形成的? –