program ending suddenly

  • 12 years ago

    hi everyone. im really in the need of some help here. if someone could look over this code and see any problems, please let me know. heres the issue im having, when the program starts, it runs just fine. but if left running, after about 20 minutes, the program crashes, with no errors (the vista error pops saying the program has stopped working and windows is collecting information). if i run the program in the debug mode, it seems fine.
    some background: when the program loads, its spawns a class to check a device connected to a comport for status changes. when finished, it spawns again and again until the program closes. heres the code i have:

    <Microsoft.VisualBasic.ComClass()> <System.Serializable()> Public Class Form1
    Private WC As Class2
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ..onload event of the main form
    .... other stuff that i dont think i a problem
    ....if i remove this bit, the program runs fine
            WC = New Class2
            ThreadPool.QueueUserWorkItem(AddressOf WC.FindMyPort)
            WC.Mycontinue = True
            If Err.Number = 0 Then
            ElseIf Err.Number = 5 Then
            End If
        End Sub
    end class

    class two code:

    Option Compare Text
    Imports System.Windows.Forms
    Imports System.Data.OleDb
    Imports System
    Imports System.Data
    Imports GsmComm.GsmCommunication
    Imports GsmComm.PduConverter
    Imports System.Text
    Imports System.Threading
    Public Class Class2
    Public Mycontinue As Boolean = True
        Public Sub FindMyPort()
            Dim storage = PhoneStorageType.Sim
            Dim MsgLocation As Integer
            Dim counter As Integer = 0
            Dim GetManu As String = ""
                comm = New GsmCommMain(9, 9600)
                IsConnected = True
                counter = 0
                    Dim info As IdentificationInfo = comm.IdentifyDevice
                    GetManu = info.Manufacturer
                Catch ex As Exception
                    Debug.Print("error getting manufacutarer")
                End Try
                If GetManu = "huawei" Then
                        Dim messages As DecodedShortMessage() = comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, PhoneStorageType.Sim)
                        For Each DecodedShortMessage In messages
                            MsgLocation = DecodedShortMessage.Index
                         '   ShowMessage(DecodedShortMessage.Data) 
    'just a function to cop to db.  program crashes even if this is never called
                            counter = counter + 1
                                comm.DeleteMessage(MsgLocation, PhoneStorageType.Sim)
                            Catch ex As Exception
                                Debug.Print("error deleting from inbox")
                                Mycontinue = False
                                Exit Sub
                                messages = Nothing
                            End Try
                    Catch ex As Exception
                        Debug.Print("error gettting inbox")
                        Mycontinue = False
                        Exit Sub
                    End Try
                    If counter > 0 Then
                        NewMsg = True
                    End If
                End If
            Catch ex As Exception
                IsConnected = False
            End Try
            Catch ex As Exception
                Debug.Print("couldnt close port")
                IsConnected = False
            End Try
            If Mycontinue = True Then
                Debug.Print("start new thread")
                Threading.ThreadPool.QueueUserWorkItem(AddressOf FindMyPort)
            End If
            storage = Nothing
            GetManu = Nothing
            MsgLocation = Nothing
            counter = Nothing
        End Sub
    End Class

    thanks for your help


Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“To iterate is human, to recurse divine” - L. Peter Deutsch