Hi,
As I understand, if a code section inside a sub called with threadX.Start
is between BeginCriticalRe gion - EndCriticalRegi on, it should complete (at
least that portion of code, not the whole 'sub'... even if a TreadX.Abort is
used, if this portion of code is running when you call that Abort.
So With this program, I would expect to print :
I'm still standing, yeh yeh yéah
Main thread finished
But only
Main thread finished
appears because thread is aborted although The code between critical region
is running... Why ?
Code:
Sub Main()
Dim myThreadx As New Thread(AddressO f subWithASleep)
myThreadx.Start ()
Thread.Sleep(20 00) 'For the called thread to have some time to enter that
"begin-critical-region"
myThreadx.Abort ()
Console.WriteLi ne("Main thread finished")
end sub
Public Sub subWithASleep()
Thread.BeginCri ticalRegion()
Thread.Sleep(15 000) 'waits 15 seconds
Console.Write(" I'm still standing, yeh yeh yéah") 'It should show
but it does NOT !
Thread.EndCriti calRegion()
End Sub
--
Roger
..NET 2005 and DB developer
As I understand, if a code section inside a sub called with threadX.Start
is between BeginCriticalRe gion - EndCriticalRegi on, it should complete (at
least that portion of code, not the whole 'sub'... even if a TreadX.Abort is
used, if this portion of code is running when you call that Abort.
So With this program, I would expect to print :
I'm still standing, yeh yeh yéah
Main thread finished
But only
Main thread finished
appears because thread is aborted although The code between critical region
is running... Why ?
Code:
Sub Main()
Dim myThreadx As New Thread(AddressO f subWithASleep)
myThreadx.Start ()
Thread.Sleep(20 00) 'For the called thread to have some time to enter that
"begin-critical-region"
myThreadx.Abort ()
Console.WriteLi ne("Main thread finished")
end sub
Public Sub subWithASleep()
Thread.BeginCri ticalRegion()
Thread.Sleep(15 000) 'waits 15 seconds
Console.Write(" I'm still standing, yeh yeh yéah") 'It should show
but it does NOT !
Thread.EndCriti calRegion()
End Sub
--
Roger
..NET 2005 and DB developer
Comment