我在VB.Net中编写了一个应用程序,不知何故崩溃没有任何理由,例如我运行它,它成功启动然后保持非活动状态10分钟或更长时间它崩溃,没有任何异常和Visual Studio告诉我,流程切换到停止模式,应用程序已关闭。
我的主要代码没有循环,只是计时器始终以100毫秒的周期启用,我不认为这是一个问题。有趣的是,进程崩溃的时间会有所不同。
我在两台Win10机器上尝试了我的应用程序。在其中一个上它根本不会崩溃,另一个有时会崩溃。我试过Win7,20分钟后经常发生崩溃--Windows说"应用程序没有响应,我们正在关闭应用程序"。那么为什么它在VS17的调试模式下没有显示任何异常,我也打开了调试菜单中的所有异常。 第一个是net运行时日志,第二个是应用程序日志:
Имя журнала: 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>
更新:我注意到串口自动连接代码中的问题:
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