0

I wrote an application in VB.Net, and somehow it crashes without a reason, for example I run it, it started successfully then after staying non-active for like 10 or more minutes it crashes, without any exception and Visual Studio tells me that process switched to stop mode and application was closed.

My main code isn't looping except that a timer is always enabled with 100ms period, i don't think this is a problem. The funny thing is that the time when process will crash varies.

I tried my application on two Win10 machines. On one of them it doesn't crash at all, and on the other one sometimes crashes. And I tried on Win7, crashes happen regularly after 20min - Windows says "application is not responding, we are closing the app". So why it doesn't show any exceptions in debug mode of VS17, also i turned on all exceptions in debug menu. first is net runtime log and second is application log:

Имя журнала:   Application
Источник:      .NET Runtime
Дата:          28.04.2018 18:40:02
Код события:   1026
Категория задачи:Отсутствует
Уровень:       Ошибка
Ключевые слова:Классический
Пользователь:  Н/Д
Компьютер:     HV-service-ПК
Описание:
Application: SD CARD Car Master [beta].exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException
Stack:
   at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef)
   at System.StubHelpers.StubHelpers.SafeHandleAddRef(System.Runtime.InteropServices.SafeHandle, Boolean ByRef)
   at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(Microsoft.Win32.SafeHandles.SafeFileHandle, System.Threading.NativeOverlapped*, Int32 ByRef, Boolean)
   at System.IO.Ports.SerialStream+EventLoopRunner.WaitForCommEvent()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

Xml события:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name=".NET Runtime" />
    <EventID Qualifiers="0">1026</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2018-04-28T07:40:02.000000000Z" />
    <EventRecordID>533</EventRecordID>
    <Channel>Application</Channel>
    <Computer>HV-service-ПК</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Application: SD CARD Car Master [beta].exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException
Stack:
   at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef)
   at System.StubHelpers.StubHelpers.SafeHandleAddRef(System.Runtime.InteropServices.SafeHandle, Boolean ByRef)
   at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(Microsoft.Win32.SafeHandles.SafeFileHandle, System.Threading.NativeOverlapped*, Int32 ByRef, Boolean)
   at System.IO.Ports.SerialStream+EventLoopRunner.WaitForCommEvent()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Data>
  </EventData>
</Event>

Имя журнала:   Application
Источник:      Application Error
Дата:          28.04.2018 18:31:18
Код события:   1000
Категория задачи:(100)
Уровень:       Ошибка
Ключевые слова:Классический
Пользователь:  Н/Д
Компьютер:     HV-service-ПК
Описание:
Имя сбойного приложения: SD CARD Car Master [beta].exe, версия: 1.0.0.0, отметка времени: 0x5ae2a828
Имя сбойного модуля: KERNELBASE.dll, версия: 6.1.7601.17514, отметка времени 0x4ce7b8f0
Код исключения: 0xe0434352
Смещение ошибки: 0x0000b760
Идентификатор сбойного процесса: 0xc9c
Время запуска сбойного приложения: 0x01d3dec2dcbdc3d0
Путь сбойного приложения: C:\Users\HV-service\Desktop\SD CARD Car Master [beta].exe
Путь сбойного модуля: C:\Windows\system32\KERNELBASE.dll
Код отчета: 238f20b0-4ab6-11e8-b866-001b3822ff72
Xml события:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Application Error" />
    <EventID Qualifiers="0">1000</EventID>
    <Level>2</Level>
    <Task>100</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2018-04-28T07:31:18.000000000Z" />
    <EventRecordID>531</EventRecordID>
    <Channel>Application</Channel>
    <Computer>HV-service-ПК</Computer>
    <Security />
  </System>
  <EventData>
    <Data>SD CARD Car Master [beta].exe</Data>
    <Data>1.0.0.0</Data>
    <Data>5ae2a828</Data>
    <Data>KERNELBASE.dll</Data>
    <Data>6.1.7601.17514</Data>
    <Data>4ce7b8f0</Data>
    <Data>e0434352</Data>
    <Data>0000b760</Data>
    <Data>c9c</Data>
    <Data>01d3dec2dcbdc3d0</Data>
    <Data>C:\Users\HV-service\Desktop\SD CARD Car Master [beta].exe</Data>
    <Data>C:\Windows\system32\KERNELBASE.dll</Data>
    <Data>238f20b0-4ab6-11e8-b866-001b3822ff72</Data>
  </EventData>
</Event>

Update: I noticed that the problem in the serial port autoconnect code:

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Connected = False
   autoconnect()
    End Sub
 Private Sub autoconnect()

        For Each sp As String In My.Computer.Ports.SerialPortNames
            Try
                spObj = New SerialPort(sp, 115200, Parity.None, 8, StopBits.One)
                spObj.ReadTimeout = 5000
                '    spObj.ReceivedBytesThreshold = 6
                spObj.WriteTimeout = 5000
                spObj.Open()

                Dim ListeningWatch As New Stopwatch
                Dim serialMessage As String

                Dim BytesToSend(1) As Byte
                Dim OutBuffer
                BytesToSend(0) = Hex(99)             ' call Dump eeprom (44)
                BytesToSend(1) = 0                   'dummy
                OutBuffer = BytesToSend

                ' Bytes are outputted in the order of their Index Number(Index)!

                spObj.Write(OutBuffer, 0, OutBuffer.length)

                ListeningWatch.Start()
                While ListeningWatch.ElapsedMilliseconds < 5000 And ListeningWatch.IsRunning
                    serialMessage = spObj.ReadExisting()
                    'RichTextBox1.Text = serialMessage
                    If serialMessage.Contains("000001020") And serialMessage.Length = 12 Then
                        ListeningWatch.Stop()

                        Connected = True
                        Timer1.Enabled = False
                        DeviceStatus.Text = "SN: " & serialMessage                       
                        Exit For
                    End If
                End While
            Catch ex As Exception
                spObj.Dispose()
            End Try
        Next
        If Connected = False Then
            DeviceStatus.Text = "SN: Not connected"
        End If
    End Sub
Cœur
  • 37,241
  • 25
  • 195
  • 267
kooda
  • 11
  • 8
  • 1
    Have you checked event log > Application? It usually logs all such mysterious process crashes. – Tanveer Badar Apr 28 '18 at 07:33
  • Check the console output, here you will able to find the exception. This usually happen when you put a `TryCatch` block on a specific code and then `rethrow` the exception but not manage it. – L. Page Apr 28 '18 at 07:35
  • If the "doesn't respond" window opens then the error is definitely logged in the Event Log. Look for an entry that says _"Application Error"_. If you've never used the Event Viewer before see this: [**What is the Windows Event Viewer, and How Can I Use It?**](https://www.howtogeek.com/123646/htg-explains-what-the-windows-event-viewer-is-and-how-you-can-use-it/) – Visual Vincent Apr 28 '18 at 07:37
  • @L.Page what is console output? – kooda Apr 28 '18 at 07:40
  • @L.Page : If the VS debugger is unable catch the exception then I don't think it is logged in the console either. – Visual Vincent Apr 28 '18 at 07:43
  • @VisualVincent ill try Event Viewer ( never used it). – kooda Apr 28 '18 at 07:48
  • @kooda : Great! In addition to my previous comment you can also look for an entry called _".NET Runtime Error"_. – Visual Vincent Apr 28 '18 at 07:48
  • @VisualVincent i debuged errors with EV as you suggested, in app's error it says that KernelBase cause the crash, and in .net error it shows "System.ObjectDisposedException Stack" ill update an qustion aboe with the logs – kooda Apr 28 '18 at 08:31
  • What does your application do? Based on the error it appears to be trying to access a serial port that has been disposed. – Visual Vincent Apr 28 '18 at 10:26
  • Also see these two related posts: [**\[ 1 \]**](https://stackoverflow.com/a/22077818), [**\[ 2 \]**](https://stackoverflow.com/q/3808885) – Visual Vincent Apr 28 '18 at 10:30
  • yes, its trying to autoconnect to serialport, but i dont know how to handle it – kooda Apr 28 '18 at 10:43
  • i debugged, and yes the error is on this code(ill update) – kooda Apr 28 '18 at 10:43
  • You never close or dispose those serial ports when you're done using them (apart from when an error occurs). You must do so before `Next`. To avoid further exceptions insert a null-check as well: `If spObj IsNot Nothing Then spObj.Dispose()`. Also try using the `ExSerialPort` class instead which can be found in an answer in the second link that I shared. – Visual Vincent Apr 28 '18 at 20:33
  • Calling the `Hex` method on your byte value of 99 seems strange. `Hex` returns a `String` but you are assigning it to an array index of type `Byte`. It seems that you do you have `Option Strict On`. – Chris Dunaway Apr 30 '18 at 15:06

0 Answers0