2

我在我的 .NET 项目(WinForms)中使用 agsXMPP 我有以下代码块,只要从任何客户端收到消息,就会执行此代码块。现在,每当收到一条消息时,这个块就会执行并且程序终止.. :( 我不知道发生了什么。帮助!

这与线程有关吗?(我听说 agsXMPP 封装了它工作的线程)

   Private Sub messageReceived(ByVal sender As Object, ByVal msg As protocol.client.Message)
    Dim chatMessage() As String
    Static Dim Hi_ed As Integer = 0
    chatMessage = msg.From.ToString.Split("/")
    Dim chatSender As String = chatMessage(0)

    If Not IsWorking Then
        IsWorking = True
        If Not ProcessCommands(msg.Body, chatSender) Then
            Dim sStr As String = ParseEnglish(msg.Body)

            Select Case sStr
                Case "HI"
                    If Hi_ed = False Then
                        SendGTalkMsg("Hi. How do you do?", chatSender)
                        Hi_ed = True
                    Else
                        SendGTalkMsg("हाय वाई कुछ नहीं हम तो !!!", chatSender)
                    End If
                Case "DETAILS PLEASE"
                    SendGTalkMsg(". Currently there are N no of sams running on me: :)", chatSender)
            End Select
        End If
        IsWorking = False

        Exit Sub
    Else
        SendGTalkMsg("I'm working right now. Please have patience.", chatSender)
    End If
End Sub

**编辑* *** 现在,当我运行生成的 EXE 文件时,在此事件完成后出现“不响应”错误,这显然意味着存在异常,但它正在逃避 try catch 块。:(

这是我得到的错误:

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01:   updatecheck.exe
Problem Signature 02:   1.0.0.0
Problem Signature 03:   4e8ed73e
Problem Signature 04:   mscorlib
Problem Signature 05:   4.0.0.0
Problem Signature 06:   4dd23522
Problem Signature 07:   1526
Problem Signature 08:   4f
Problem Signature 09:   System.InvalidOperationException
OS Version:  6.1.7600.2.0.0.256.1
Locale ID:  1033
Additional Information 1:   0a9e
Additional Information 2:   0a9e372d3b4ad19135b953a78882e789
Additional Information 3:   0a9e
Additional Information 4:   0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement       
offline:
C:\Windows\system32\en-US\erofflps.txt
4

2 回答 2

2

好,好,好。这完全是因为一个愚蠢的对话框

My.Computer.Network.DownloadFile(SourceZipFile, DestinationZipFile, "<userid>", "<password>", True, 100000, True)

设置为真。因此,每当出现文件下载进度框时,它都会把线程搞得一团糟。当我将DownloadFile的ShowUI参数更改为False时,一切正常。:)

但是我们对此有明确的解释吗?

于 2011-10-07T13:26:33.233 回答
0

这很可能是由于线程和未处理异常的组合。似乎没有办法控制除主线程之外的任何未处理异常的行为,因此您必须处理可能在主线程之外出现的所有异常。这包括异步回调,例如上面的,因为这些通常是在主线程之外进行的。如果在非主线程上未处理异常,应用程序将简单地终止;没有消息。

我建议将所有回调和其他异步方法包装在一个 try...catch 块中,该块记录错误或将其写入调试跟踪窗口。

于 2011-10-07T05:35:57.733 回答