Я выполняю асинхронную подпрограмму, чтобы продолжать слушать UDP-клиент. Когда я получаю сообщение, я обновляю поток пользовательского интерфейса, используя BeginInvoke. Но теперь, когда я снова открываю форму, у меня возникает проблема. Это вызовет исключение. Невозможно получить доступ к удаленному объекту. Имя объекта: 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
Я с нетерпением жду решения. Спасибо.
Можете ли вы показать нам код, который вы используете, чтобы вновь открыть форму? –