Threads and ...CriticalRegion

Visual Studio29
Hi,



I have the following code that uses beginCriticalRegion and

EndCriticalRegion



Imports System.Threading

Public Class Form1

Shared Sub SimpleWorks(ByVal o As Object)

Dim info As person = CType(o, person)



Thread.BeginCriticalRegion()

Thread.Sleep(100)

MsgBox(Thread.CurrentThread.ManagedThreadId & " " & info.Name)

Thread.EndCriticalRegion()

End Sub

Dim operation As New ParameterizedThreadStart(AddressOf

SimpleWorks)



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click



Dim theThreads1 As New Thread(operation)

Dim P1 As New person("mimi", " rogers")

theThreads1.Start(P1)



Dim P2 As New person("Ina", "Forrester")



Dim theThreads2 As New Thread(operation)

theThreads2.Start(P2)





'HERE IS NOT WORKING

theThreads2.Abort()



Dim P3 As New person("Dave", "Simpson")

Dim theThreads3 As New Thread(operation)

theThreads3.Start(P3)



End Sub

End Class



I find that theThreads2 is still aborted before displaying the message:

Msgbox.......



Can somebody enlighten me.



Thank you,



Carly


-