L
Lucvdv
Can someone explain why this code pops up a messagebox saying the
ThreadAbortException wasn't handled?
The first exception is reported only in the debug pane, as expected.
The second (caused by thread.Abort()) is reported twice: once in the debug
window, and once through the message box.
Is it because the thread was sleeping when the exception occurred?
Imports System.Threading
[...]
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, _
AddressOf UnhandledExceptionHandler
Try
Throw New Exception("This is a test")
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
Dim t As New Thread(AddressOf ThreadProc)
t.Start()
Thread.Sleep(1000)
t.Abort()
End Sub
Private Sub UnhandledExceptionHandler(ByVal sender As Object, _
ByVal args As UnhandledExceptionEventArgs)
MsgBox("Unhandled " & args.ExceptionObject.GetType.ToString())
End Sub
Private Sub ThreadProc()
Try
Do
Thread.Sleep(100)
Loop
Catch ex As ThreadAbortException
Debug.WriteLine(ex.ToString)
End Try
End Sub
ThreadAbortException wasn't handled?
The first exception is reported only in the debug pane, as expected.
The second (caused by thread.Abort()) is reported twice: once in the debug
window, and once through the message box.
Is it because the thread was sleeping when the exception occurred?
Imports System.Threading
[...]
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, _
AddressOf UnhandledExceptionHandler
Try
Throw New Exception("This is a test")
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
Dim t As New Thread(AddressOf ThreadProc)
t.Start()
Thread.Sleep(1000)
t.Abort()
End Sub
Private Sub UnhandledExceptionHandler(ByVal sender As Object, _
ByVal args As UnhandledExceptionEventArgs)
MsgBox("Unhandled " & args.ExceptionObject.GetType.ToString())
End Sub
Private Sub ThreadProc()
Try
Do
Thread.Sleep(100)
Loop
Catch ex As ThreadAbortException
Debug.WriteLine(ex.ToString)
End Try
End Sub