gpt4 book ai didi

.net - On On Error Resume Next时出错

转载 作者:行者123 更新时间:2023-12-02 11:14:38 35 4
gpt4 key购买 nike

我无法建立exe:

1> ------ Assembly started: project: B, Configuration: Debug Any CPU

B.vb (38.9): error BC36595: The method can not simultaneously contain an "On Error Resume Next" statement and define a variable that is used in the lambda expression or query expression.

Assembling: successful: 0, with errors: 1, no change: 0, skipped: 0



从第37行到第48行:
Sub Read(ByVal ar As IAsyncResult)
On Error Resume Next
If TCP.GetStream.DataAvailable And TCP.GetStream.CanRead Then
Dim tt As New Thread(AddressOf Data) : tt.IsBackground = True : tt.SetApartmentState(ApartmentState.STA) : tt.Start(DirectCast(bf.Deserialize(TCP.GetStream), Byte()))
TCP.GetStream.Flush() : TCP.GetStream.BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
Exit Sub
Else
GoTo r
End If
r:
Disconnect()
End Sub

我正在尝试使用try \ catch,但是不知道,对吗? :
Sub Read(ByVal ar As IAsyncResult)
Try
If TCP.GetStream.DataAvailable And TCP.GetStream.CanRead Then
Dim tt As New Thread(AddressOf Data) : tt.IsBackground = True : tt.SetApartmentState(ApartmentState.STA) : tt.Start(DirectCast(bf.Deserialize(TCP.GetStream), Byte()))
TCP.GetStream.Flush() : TCP.GetStream.BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
Exit Sub
End If
Catch
GoTo r
Finally
End Try
r:
Disconnect()
End Sub

最佳答案

该错误消息上的documentation告诉您如何解决它:

To correct this error

  1. Replace the exception handling code that uses the On Error Goto statement with a Try...Catch statement.

试用...捕获将包含以下部分:
  • Try-应该执行什么
  • Catch-如果在Try
  • 中引发异常,应该执行什么操作
  • Finally-无论是否存在异常,应执行什么操作。

  • I'm trying to use try\catch, but don't know, is that correct?


    它可能有效,但是 Exit SubGoto是不必要的并且使事情变得困惑。我会尝试:
    Sub Read(ByVal ar As IAsyncResult)
    Try
    If TCP.GetStream.DataAvailable And TCP.GetStream.CanRead Then
    Dim tt As New Thread(AddressOf Data) : tt.IsBackground = True : tt.SetApartmentState(ApartmentState.STA) : tt.Start(DirectCast(bf.Deserialize(TCP.GetStream), Byte()))
    TCP.GetStream.Flush() : TCP.GetStream.BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
    End If
    Catch
    Disconnect()
    Finally
    End Try
    End Sub
    但是,只有在出现异常时才调用 Disconnect()似乎很奇怪。否则连接应该保持打开状态吗? call 者如何知道是否已调用 Disconnect

    关于.net - On On Error Resume Next时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43765062/

    35 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com