Solved

.NET Runtime 2.0 Error and Appication Hang

Posted on 2007-03-21
11
3,697 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 

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 86

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 86

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 86

Accepted Solution

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

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 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