old problem, revisited

dreamdelerium

Active member
Joined
Mar 7, 2008
Messages
36
Programming Experience
1-3
hi everyone. i thought i fixed this problem but it keeps coming back. i have a usb modem connected to my computer (which can send and recieve sms's). my program's main thread is used to read/send sms's and store them in a db. a secondary thread polls the modem looking for new text messages (about once every 3 seconds). after running about an hour (sometimes sooner) the program gets disconnected from the commport (it use to crash the program but ive seemed to fix that) and wont reconnect. heres the relevant code:

Main Form:
VB.NET:
.....
Delegate Sub TaskDelegate()
........
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            If IsConnected = False Then
                Me.Label12.Text = "Not Connected"
            Else
                Me.Label12.Text = "Connected"
            End If

            If NewMsg = True Then
                Me.Label10.Text = (CInt(Me.Label10.Text) + 1).ToString
                NewMsg = False
            Else

            End If


            Dim someClass As New Class2
            Dim td As New TaskDelegate(AddressOf someClass.FindMyPort)
            td.BeginInvoke(Nothing, Nothing)

        Catch ex As Exception
            MsgBox("An error has occured.  Please make sure the programs database is closed.")
        End Try
    End Sub


Class2 thread:

VB.NET:
Public Class Class2
Delegate Sub TaskDelegate()

Public sub ShowMessage (ByRef MsgPDU As SmsDeliverPdu)
'not important because this is not called if no sms comes in, which they 
'dont when i test it
end sub

    Public Sub FindMyPort()
        Dim storage = PhoneStorageType.Sim
        Dim MsgLocation As Integer
        Dim counter As Integer = 0
        Dim GetManu As String = ""

        Debug.Print("Start Class findmyport")
        Debug.Print(MyPortNumber)


        comm = New GsmCommMain(MyPortNumber, 9600)
        Dim nullCheck = IsDBNull(comm)
        If nullCheck = True Then
            Debug.Print("port is null")
        Else
            If comm.IsOpen = True Then
                comm.Close()
                Thread.CurrentThread.Abort()
                Exit Sub
            Else
                Try

                    comm.Open()
                    counter = 0
                    Try
                        IsConnected = True
                        Dim messages As DecodedShortMessage() = comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, PhoneStorageType.Sim)
                        For Each DecodedShortMessage In messages
                            MsgLocation = DecodedShortMessage.Index
                            counter = counter + 1
                            Try
                                comm.DeleteMessage(MsgLocation, PhoneStorageType.Sim)
                            Catch ex As Exception
                                Debug.Print("error deleting from inbox")
                                Exit Sub
                            Finally
                                messages = Nothing
                            End Try
                            ShowMessage(DecodedShortMessage.Data)
                        Next
                    Catch ex As Exception
                        Debug.Print("error gettting inbox")
                        Exit Sub
                    End Try

                    If counter > 0 Then
                        NewMsg = True
                    End If

                Catch ex As GsmComm.GsmCommunication.CommException
                    IsConnected = False
                    Debug.Print("error:" & ex.InnerException.Message)

                    If comm.IsOpen = True Then
                        comm.Close()
                    End If
                  Finally
                    If comm.IsOpen = True Then
                        comm.Close()
                    End If
                End Try
            End If
        End If

        storage = Nothing
        GetManu = Nothing
        MsgLocation = Nothing
        counter = Nothing
        GC.Collect()
        Debug.Print("exiting sub")
    End Sub

end class

and here is the error i get after it runs for an hour or so:

A first chance exception of type 'GsmComm.GsmCommunication.CommException' occurred in GSMCommunication.dll
error:The process cannot access the port 'COM6' because it is being used by another process.

what could be using the port? i have no other application running that would use it. is it something to do with the thread? do i need to destroy the thread after its run? if so, how?
 
comm error

so i ran a port listener while my program was running and got this: (see log in attachment)

what does this mea and what could be causing these errors?
 

Attachments

  • lengthy log.zip
    36.7 KB · Views: 24
Last edited by a moderator:
Next time you may want to consider NOT spamming the forum with a 6041 lines long log output. I'd put that in a text file and attach it to the post. Text content is also highly compressable, so instead of wasting space and bandwidth for a 500KB file you see a 36KB zip suffice here.
 
Back
Top