Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Visual Studio .NET > Testing, Quality Control, Debugging

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-12-2008, 7:05 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.0 (VS 2005/2008)
 
Join Date: Mar 2008
Posts: 36
Reputation: 27
dreamdelerium is on a distinguished programming path ahead
Default even more thread problems: error catching

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:

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
and heres the functio it calls:

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
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 8:10 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.