Solved

.NET Runtime 2.0 Error and Appication Hang

Posted on 2007-03-21
11
3,686 Views
Last Modified: 2013-11-26
I have an application developed with VisualBasic 2005 that use .Net Framework 2.0. This application works 24 Hours day, 7 days at week. It works fine but sometimes i have two errors that crash the application on the event viewer I see:
First
Appication Hang
Category (101)
ID event : 1002
Application PlateReader.exe version 1.0.0.0, module hungapp, version 0.0.0.0 address 0x00000000

Second
.NET Runtime 2.0 Error
Category: nothing
ID event: 1000
Faulting application plate_reader.exe, version 1.0.0.0, stamp 45f6a516, faulting module ntdll.dll, version 5.1.2600.2180, stamp 41252c01, debug? 0, fault address 0x0001142e.

Please help me extremely important
 

 
0
Comment
Question by:mpbejo
  • 4
  • 3
11 Comments
 
LVL 21

Expert Comment

by:tovvenki
ID: 18762556
Hi,
This does not provide us much information. can you tell us under what scenario or action does the application fails. What it does? so that it will be help ful to analyse and provide a soltuion

Kind regards
venki
0
 

Author Comment

by:mpbejo
ID: 18764330
The application is a plate reader, the application receive images froma a camera, the image is converted to text, on a another pc there is a sql2000 server with a database, the application run a query to find the text on the database, if found the application send, via RS485 (COM3) a command to a module ADAM 4060 that open a "door", if the plate is not recognized it is possible to press a button this signal goes to a module ADAM 4052 and send to the computer via RS485 (COM4) the application intercepts this, and send an alarm to the control room so they can decide to open or not. All this operations are executed by a timer every 250ms.
The application can works fine for two or three days withuot problem, and in a day can i hae 1000 plate recognized. I did not find a point where tha application crash.
I hope this is useful  
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18765781
"All this operations are executed by a timer every 250ms."

Are you turning off the Timer upon entry...and then turning it back on at the end?

    Private Sub tmr_XXX(...) Handles tmr.YYY
        tmr.Stop()

        ' stuff in here...

        tmr.Start()
    End Sub

Other than that, I think we would have to see your code to be any more helpful...
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:mpbejo
ID: 18769654
Yes the timer is turn offat the beginning and turn on at the end
Here the code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim ec As Integer
        Dim emsg As String
        Dim ptext As String 'Numero Targa
        Dim ptext_Stato As String ' Numero Targa Enti statali
        Dim cf As Integer 'Accuratezza targa acquisita
        Dim pt As Integer 'tipo targa
        Dim Targa_DB, RagSoc_DB, Nome_DB, Cognome_DB, Categoria_DB, Marca_DB, Modello_DB, Attivo_DB As String
        Dim Ora_Inizio_DB As Date
        Dim Ora_Fine_DB As Date
        Dim Data_Inizio_DB As Date
        Dim Data_Fine_DB As Date
        Dim Data_Ora_Att As Date
        Dim OraIni, MinIni, SecIni, OraFin, MinFin, SecFin, OraAtt, MinAtt, SecAtt As Integer
        Targa_DB = ""
        Attivo_DB = "NO"
        'disabilita il timer
        Timer1.Enabled = False
        PictureBox1.Image = New System.Drawing.Bitmap("C:\Luce_off.bmp")
        If (CapError = False) Then
            'Cattura immagine
            Cmanpr1.UpdateImage()
            'Legge la targa
            If (Cmanpr1.ReadPlate <> 0) Then
                If (Cmanpr1.GetPlate(ptext, cf, pt) = 0) Then
                    ptext = "Nessuna Targa"
                Else
                    'Scrive a video la targa
                    Gxlabel1.WriteText(ptext)
                    If (ptext.Length <> 14) Then
                        Try
                            cnn1.Open()
                            OraAtt = Date.Now.Hour * 3600
                            MinAtt = Date.Now.Minute * 60
                            SecAtt = Date.Now.Second
                            If (ptext <> ptextprec) And (ptext <> ptextprec2) Then
                                ptextprec2 = ptextprec
                                ptextprec = ptext
                                ptext_Stato = ptext
                                Label2.Text = ptextprec
                                Label3.Text = ptextprec2
                                If (ptext_Stato.Length >= 5) Then
                                    ptext_Stato = ptext_Stato.Substring(ptext_Stato.Length - 5, 5)
                                    Label3.Text = ptext_Stato
                                End If
                                'Verifico se la targa letta è nel database
                                Dim sqlQuery As String
                                If (SELEZIONE = 1) Then
                                    sqlQuery = "SELECT Targa, Ora_Inizio, Ora_Fine, Data_Inizio,Data_Fine, Attivo FROM Consensi WHERE Targa = '" & ptext & "' OR Targa Like '%" & ptext_Stato & "%'"
                                Else
                                    sqlQuery = "SELECT Targa, Ora_Inizio, Ora_Fine, Data_Inizio,Data_Fine, Attivo FROM Consensi WHERE Targa = '" & ptext & "'"
                                End If
                                Dim cmd1 As New SqlCommand(sqlQuery, cnn1)
                                Dim rdr1 As SqlDataReader
                                rdr1 = cmd1.ExecuteReader()
                                Try
                                    Do While rdr1.Read()
                                        'Carico i dati della query nelle variabili
                                        Targa_DB = rdr1.GetString(0)
                                        Ora_Inizio_DB = rdr1.GetDateTime(1)
                                        Ora_Fine_DB = rdr1.GetDateTime(2)
                                        Data_Inizio_DB = rdr1.GetDateTime(3)
                                        Data_Fine_DB = rdr1.GetDateTime(4)
                                        Attivo_DB = rdr1.GetString(5)
                                    Loop
                                Catch ex As Exception
                                    If (errlog <> ex.Message.ToString) Then
                                        Log.Write(Date.Now & " ")
                                        Log.WriteLine(ex.Message.ToString)
                                        errlog = ex.Message.ToString
                                    End If
                                    'MessageBox.Show(ex.Message)
                                Finally
                                    rdr1.Close()
                                End Try
                                If (Attivo_DB <> "NO") Or (Targa_DB.Length = 0) Then
                                    If (Targa_DB.Length > 0) Then
                                        'Controllo se la targa ha i parametri data
                                        'e ora iniziale e finale per il passaggio in regola

                                        OraIni = Ora_Inizio_DB.Hour * 3600
                                        MinIni = Ora_Inizio_DB.Minute * 60
                                        SecIni = Ora_Inizio_DB.Second
                                        OraFin = Ora_Fine_DB.Hour * 3600
                                        MinFin = Ora_Fine_DB.Minute * 60
                                        SecFin = Ora_Fine_DB.Second

                                        'salvo l'immagine del passaggio
                                        Dim Salva As String = Targa_DB & Date.Now.Year & Date.Now.Month & Date.Now.Day & Date.Now.Hour & Date.Now.Minute & Date.Now.Second & ".jpeg"
                                        GxImage1.SaveView(Salva, GXIMAGE_OCXLib.enumFileFormat.GX_JPEG)
                                        Dim Img As System.Drawing.Image
                                        Dim strm As New System.IO.MemoryStream
                                        Img = System.Drawing.Image.FromFile(Salva)
                                        Img.Save(strm, Img.RawFormat)
                                        Dim Contenuto() As Byte = strm.ToArray


                                        Dim cmd2 As New SqlCommand
                                        'Costruisco la stringa Data da salvare nella tabella passaggi
                                        Dim Data As String = Date.Now.Day.ToString & "/" & Date.Now.Month.ToString() & _
                                            "/" & Date.Now.Year.ToString() & " " & Date.Now.Hour.ToString() & ":" & _
                                            Date.Now.Minute.ToString() & ":" & Date.Now.Second.ToString()

                                        'Controllo la data validità e ora inizio/fine per
                                        'abilitare il passaggio
                                        If ((Date.Today.Date() >= Data_Inizio_DB.Date()) And (Date.Today.Date() <= Data_Fine_DB.Date())) Then
                                            If ((OraAtt + MinAtt + SecAtt) >= (OraIni + MinIni + SecIni)) And ((OraAtt + MinAtt + SecAtt) <= (OraFin + MinFin + SecFin)) Then
                                                'Chiudo il relè per alzare la sbarra
                                                PictureBox1.Image = New System.Drawing.Bitmap("C:\Luce_on.bmp")
                                                SerialPort1.PortName = SERIALE
                                                SerialPort1.Open()
                                                Try
                                                    SerialPort1.Write("#010001" + ControlChars.Cr)
                                                Catch ex As Exception
                                                    If (errlog <> ex.Message.ToString) Then
                                                        Log.Write(Date.Now & " ")
                                                        Log.WriteLine(ex.Message.ToString)
                                                        errlog = ex.Message.ToString
                                                    End If
                                                    'MessageBox.Show(ex.Message)
                                                Finally
                                                    SerialPort1.Close()
                                                End Try

                                                'salvo l'evento di passaggio consentito nella tabella passaggi
                                                cmd2.CommandText = "INSERT Passaggi " & "(IDTarga, DataOra_Passaggio,Autorizzato,Image) VALUES " & _
                                                "('" & Targa_DB & "', getdate(), 'SI', @theImage)"

                                                Dim theImageParameter As New SqlParameter("@theImage", SqlDbType.Image)
                                                theImageParameter.Value = Contenuto
                                                cmd2.Parameters.Add(theImageParameter)
                                                cmd2.Connection = cnn1
                                                Try
                                                    cmd2.ExecuteNonQuery()
                                                Catch ex As Exception
                                                    If (errlog <> ex.Message.ToString) Then
                                                        Log.Write(Date.Now & " ")
                                                        Log.WriteLine(ex.Message.ToString)
                                                        errlog = ex.Message.ToString
                                                    End If
                                                    'MessageBox.Show(ex.Message)
                                                End Try

                                                'riapro il relè la sbarra
                                                'verrà gestita delle fotocellule
                                                Timer2.Enabled = True
                                            Else
                                                'salvo l'evento di passaggio non consentito per ora non valida nella tabella passaggi
                                                cmd2.CommandText = "INSERT Passaggi " & "(IDTarga, DataOra_Passaggio,Autorizzato,Image) VALUES " & _
                                                "('" & Targa_DB & "', getdate(), 'Ora non valida', @theImage)"

                                                Dim theImageParameter As New SqlParameter("@theImage", SqlDbType.Image)
                                                theImageParameter.Value = Contenuto
                                                cmd2.Parameters.Add(theImageParameter)
                                                cmd2.Connection = cnn1
                                                Try
                                                    cmd2.ExecuteNonQuery()
                                                Catch ex As Exception
                                                    If (errlog <> ex.Message.ToString) Then
                                                        Log.Write(Date.Now & " ")
                                                        Log.WriteLine(ex.Message.ToString)
                                                        errlog = ex.Message.ToString
                                                    End If
                                                    'MessageBox.Show(ex.Message)
                                                End Try
                                            End If
                                        Else
                                            'salvo l'evento di passaggio non consentito per data non valida nella tabella passaggi
                                            cmd2.CommandText = "INSERT Passaggi " & "(IDTarga, DataOra_Passaggio,Autorizzato,Image) VALUES " & _
                                            "('" & Targa_DB & "', getdate(), 'Data non valida', @theImage)"

                                            Dim theImageParameter As New SqlParameter("@theImage", SqlDbType.Image)
                                            theImageParameter.Value = Contenuto
                                            cmd2.Parameters.Add(theImageParameter)
                                            cmd2.Connection = cnn1
                                            Try
                                                cmd2.ExecuteNonQuery()
                                            Catch ex As Exception
                                                If (errlog <> ex.Message.ToString) Then
                                                    Log.Write(Date.Now & " ")
                                                    Log.WriteLine(ex.Message.ToString)
                                                    errlog = ex.Message.ToString
                                                End If
                                                'MessageBox.Show(ex.Message)
                                            End Try
                                        End If
                                        Img.Dispose()
                                        System.IO.File.Delete(Salva)
                                    End If
                                End If
                            End If
                        Catch ex As Exception
                            If (errlog <> ex.Message.ToString) Then
                                Log.Write(Date.Now & " ")
                                Log.WriteLine(ex.Message.ToString)
                                errlog = ex.Message.ToString
                            End If
                            'MessageBox.Show(ex.Message)
                        Finally
                            cnn1.Close()
                        End Try
                    End If
                End If
            End If
        End If
        'Controllo del bottone citofono
        Try
            SerialPort2.Write("$026" + ControlChars.Cr)
        Catch ex As Exception
            If (errlog <> ex.Message.ToString) Then
                Log.Write(Date.Now & " ")
                Log.WriteLine(ex.Message.ToString)
                errlog = ex.Message.ToString
            End If
            'MessageBox.Show(ex.Message)
        End Try
        'Riabilita il timer
        Timer1.Enabled = True
    End Sub
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18771905
I don't work with databases so I don't know if there are any improvements that can be made there.

You are creating images alot which is pretty resource intensive though.

Your "on" and "off" images should just be created once and then toggled back and forth instead of being recreated each time.  This way you don't have the Garbage collector constantly disposing of an image you are just going to use again:

    Private imgOn As Image = Image.FromFile("C:\Luce_on.bmp")
    Private imgOff As Image = Image.FromFile("C:\Luce_off.bmp")

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ...

        Timer1.Enabled = False
        PictureBox1.Image = imgOff

        ...

                                        PictureBox1.Image = imgON

        ...
    End Sub

Try disposing of things as soon as you are done with them.  Also try opening the image with a Stream instead of Image.FromFile():

        'salvo l'immagine del passaggio
        Dim Salva As String = Targa_DB & Date.Now.ToString("yyyyMMddhhmmss") & ".jpeg"
        GxImage1.SaveView(Salva, GXIMAGE_OCXLib.enumFileFormat.GX_JPEG)
        Dim fs As New System.IO.FileStream(Salva, IO.FileMode.OpenOrCreate)
        Dim img As Image = Image.FromStream(fs)
        fs.Close()
        Dim ms As New System.IO.MemoryStream
        img.Save(ms, img.RawFormat)
        Dim Contenuto() As Byte = ms.ToArray
        img.Dispose()
        ms.Dispose()
0
 

Author Comment

by:mpbejo
ID: 18772119
Thank You very much, for your tips I try immediately.
But a question, So do you think that the problem is not a bug in my software or in .NET framework, but only a problem of improve  the performance of this Sub.    
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18772198
It's hard to say... =\

But if this is running 24/7 every 250ms we want to reduce the amount of memory allocated at any given time.

The GC doesn't run as often as we think it should so we should .Dispose() of things quickly to help it along.

It's always possible that you have some bad RAM and the problem only occurs intermittently when you hit the "bad spot".  You never know...
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18772267
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question