Results 1 to 7 of 7

Thread: program crashes without error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    program crashes without error

    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:

    Code:
    <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
    
    errorhandler:
            If Err.Number = 0 Then
            ElseIf Err.Number = 5 Then
            Else
                MsgBox(Err.Description)
            End If
    
        End Sub
    
    end class

    class two code:

    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 = ""
            Try
                comm = New GsmCommMain(9, 9600)
                comm.Open()
                IsConnected = True
                counter = 0
                Try
                    Dim info As IdentificationInfo = comm.IdentifyDevice
                    GetManu = info.Manufacturer
    
                Catch ex As Exception
                    Thread.Sleep(6000)
                    Debug.Print("error getting manufacutarer")
                End Try
    
                If GetManu = "huawei" Then
                    Try
    
                        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
                            Thread.Sleep(1000)
                            Try
                                comm.DeleteMessage(MsgLocation, PhoneStorageType.Sim)
                            Catch ex As Exception
                                Debug.Print("error deleting from inbox")
                                Mycontinue = False
                                Exit Sub
                                Finally
                                messages = Nothing
                            End Try
                        Next
                    Catch ex As Exception
                        Debug.Print("error gettting inbox")
                        Mycontinue = False
                        Exit Sub
                    End Try
    
                    If counter > 0 Then
                        NewMsg = True
                    End If
                Else
                End If
    
    
            Catch ex As Exception
                Debug.Print(ex.ToString)
                IsConnected = False
            End Try
            Try
                comm.Close()
            Catch ex As Exception
                Debug.Print("couldnt close port")
                IsConnected = False
    
            End Try
    
            If Mycontinue = True Then
                Debug.Print("start new thread")
                Thread.Sleep(4000)
    
                Threading.ThreadPool.QueueUserWorkItem(AddressOf FindMyPort)
            Else
                Debug.Print("stopped")
            End If
            storage = Nothing
            GetManu = Nothing
            MsgLocation = Nothing
            counter = Nothing
            GC.Collect()
        End Sub
    End Class
    I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base

  2. #2
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: program crashes without error

    You need to handle the UnhandledException event of your program and dump the error to a log file. Then post the error message here and we can take a look at it. Do you know how to do this?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Re: program crashes without error

    no, i dont. can you give me some pointers?
    I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Re: program crashes without error

    ok, i found this in the help file:
    To log an unhandled exception
    Have a project selected in Solution Explorer. On the Project menu, choose Properties.

    Click the Application tab.
    Click the View Application Events button to open the Code Editor.
    This opens the ApplicationEvents.vb file.
    Have the ApplicationEvents.vb file open in the Code Editor. On the General menu, choose MyApplication Events.
    On the Declarations menu, choose UnhandledException.
    The application raises the UnhandledException event before the main application runs.
    Add the My.Application.Log.WriteException method to the UnhandledException event handler.

    and then i add this:
    Code:
    My.Application.Log.WriteException(e.Exception, _
        TraceEventType.Critical, _
        "Application shut down at " & _
        My.Computer.Clock.GmtTime.ToString)
    heres a stupid question: wheres the log kept at? how do i read it?

    also, i saw that theres a setting in the unhandled exception event that can be set so that the app isnt terminated when the event is raised. how do i change this?
    I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: program crashes without error

    On a related note, and possibly because I don't use Vista, are you sure this indicates that your program has thrown an exception? Could it just be hung somewhere?
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Re: program crashes without error

    i dont know. im knew to all this. this is actually my first program and im just teaching myself. how do i know if its "just hung" and if it is, how do i prevent it from hanging. it happens pretty regularly. i think the problem is comming from one of two places. either the usb modem that im polling is sending some strange output, which im not handling properly (but i dont know what it could be sending) or the the gsmcomm library im using is throwing some exception for some reason. the last thing i can think of is, could i be using up to much resources?
    I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base

  7. #7
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: program crashes without error

    Just hung will pop up "Not Responding". "Stopped Working" actually does indicate a crash. And the log file will be in the debug folder of your project.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width