I expect MsgBox("Exception HIT!") to be reached ... but it is not ...
Any ideas why this it isn't hit (and the thread is never aborted)?? ... The error doesn't even appear to have been raised (going to ExceptionSettings and ticking the ThreadAbortException).
Thanks in advance,
Kris
VB.Net Code:
Public Class Form1
Const ConString = "Data Source=dev-dbserver;Initial Catalog=kb_2430;Integrated Security=True"
Dim t As New System.Threading.Thread(Sub()
Try
Using con As New System.Data.SqlClient.SqlConnection(ConString)
con.Open()
Using cmd = con.CreateCommand()
cmd.CommandText = "WHILE 0 = 0 WAITFOR DELAY '01:00:00'"
cmd.ExecuteNonQuery()
End Using
End Using
'Using the below instead works as expected:
'System.Threading.Thread.Sleep(Integer.MaxValue)
Catch ex As Threading.ThreadAbortException
MsgBox("Exception HIT!")
Catch ex As Exception
MsgBox("Unhandled: " & ex.Message)
End Try
End Sub)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
t.Start()
System.Threading.Thread.Sleep(2500)
t.Abort()
End Sub
End Class
EDIT:
I suspect it may need to finish executing native code before it can terminate a thread??.. but just a guess