so, heres my issue: i have a thread that runs a function to check a wireless modem to see if theres any new sms's. every thing seems to be going well but i need to plan for the eventuallity that someone will be unplug the modem. unfortunatly, i cant seem to catch the resulting error. heres what i got:
and heres the functio it calls:Code:Public Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim j As Integer = 0 Dim i As Integer = 0 Debug.Print("bg worker begin") While i = j If BackgroundWorker1.CancellationPending Then i = 2 e.Cancel = True BackgroundWorker1.Dispose() Debug.Print("bg worker middle") Exit While Else CheckForNew() End If End While Debug.Print("bg worker end") End Sub
this function is called every second for the durration of the programs life (it check to new txt messages). i beleive the error is comming from the .open command. i also believe that because its on a different thread, the try..catch statemenst arent working properly (am i right?). the errorr thats not being caught can only be seen durring debug (durring run time of the application, the program just crashes with no error).Code:Public Sub CheckForNew() Debug.Print("checkfornew begin") Dim storage = getMessageStorage() Dim MsgLocation As Integer Dim counter As Integer = 0 Try If isPortAModem() = True Then comm = New GsmCommMain(Microsoft.VisualBasic.Right(GetPort, 1)) comm.Open() counter = 0 Try Dim messages As DecodedShortMessage() = comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, PhoneStorageType.Sim) If (messages.Length.ToString()) = 0 Then Else End If For Each DecodedShortMessage In messages MsgLocation = DecodedShortMessage.Index ShowMessage(DecodedShortMessage.Data) counter = counter + 1 comm.DeleteMessage(MsgLocation, PhoneStorageType.Sim) Next Catch ex As IOException MsgBox(ex.Message) Finally End Try Try comm.Close() Catch ex As IO.IOException End Try Else End If Debug.Print("chekcfornew end") Catch ex As Exception End Try End Sub
how do i catch this




Reply With Quote