dreamdelerium
Active member
- Joined
- Mar 7, 2008
- Messages
- 36
- Programming Experience
- 1-3
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:
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).
how do i catch this?
VB.NET:
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
and heres the functio it calls:
VB.NET:
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
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).
how do i catch this?