dreamdelerium
Active member
- Joined
- Mar 7, 2008
- Messages
- 36
- Programming Experience
- 1-3
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:
class two code:
thanks for your help
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:
VB.NET:
<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:
VB.NET:
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
thanks for your help