2011-10-07 38 views
2

任何有效的原因,我在我的.NET項目(的WinForms) 我有下面的代碼塊,這是無論何時從任何客戶端接收的消息執行使用agsXMPP。 現在,每當收到一條消息,該塊執行和程序結束.. :( 我不知道爲所發生的事情,救命啊!.NET的Winform項目終止不會對最終子

有這事做的主題?(我聽說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文件,此事件後,完成了「不-respo nding「錯誤來了,這顯然意味着有一個異常,但它逃避了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 

回答

2

嗯,好吧。全都是因爲傻對話框

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

被設置爲true。所以無論什麼時候出現文件下載進度框,它都用來搞亂線程。當我改變的顯示用戶界面參數DownloadFile,一切運行良好。 :)

但是我們對此有一個清楚的解釋嗎?

0

這很可能是由於線程的組合和未處理的異常似乎是沒有辦法控制的未處理的異常行爲任何但是主線程,所以這是你處理可能出現的主線程之外的所有異常勢在必行。這包括異步回調,如上述,因爲這些往往是截止的主線程。如果一個異常在非主線程上未處理,該應用程序將簡單地終止;無消息

我建議將所有回調和其他異步方法包裝在try ... catch塊中,以記錄錯誤或將其寫入調試跟蹤窗口。

+2

我試過了(把所有的回調試試看......但是都是徒勞的.. :() –