473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Threading problem - Tell me what I'm seeing here.

I'm trying to study for a cert and I'm writing a few examples loosely based
on Chapter 7 of the 536 manual. I am not used to thread programming. The
manual states that: 'Any attempt to abort a thread while it is within a
critical
region will have to wait until after the critical region is complete.' So,
I wrote the following class, used in a Dot Net 2.0 console app:

Imports System.Threading
Public Class Class5
Dim operation As New ThreadStart(AddressOf AbortThisThread)
Dim newThread As New Thread(operation)

Public Sub New()
newThread.Start()
Thread.Sleep(500)
newThread.Abort()
Console.WriteLine("In New, after abort, press any key...")
Console.ReadKey()
End Sub

Shared Sub AbortThisThread()
Try
Thread.BeginCriticalRegion()
Console.WriteLine("Class5:Thread: {0} in AbortThisThread sub",
Thread.CurrentThread.ManagedThreadId)
Console.ReadKey()
Console.WriteLine("In AbortThisThread, after ReadKey")
Thread.EndCriticalRegion()
Catch ex As ThreadAbortException
Console.WriteLine("Exception in AbortThisThread, error = " +
ex.Message)
End Try
End Sub

End Class

The output is as follows:

Class5:Thread: 10 in AbortThisThread sub
In New, after abort, press any key...
Exception in AbortThisThread, error = Thread was being aborted.

So it looks to me like I was able to interupt the critical region.

Comments? Am I making any sense at all? (Or does use of I/O invalidate
this begin/end scheme?)
Oct 12 '08 #1
1 1239
B. Chernick wrote:
I'm trying to study for a cert and I'm writing a few examples loosely
based on Chapter 7 of the 536 manual. I am not used to thread
programming. The manual states that: 'Any attempt to abort a thread
while it is within a critical
region will have to wait until after the critical region is
complete.' So, I wrote the following class, used in a Dot Net 2.0
console app:
Based on googling, that quote from the cert manual is incorrect. Critical
regions just indicate code that could leave an app's state corrupted if they are
aborted, allowing a host like SQL server to decide to restart the app.

There is a thing called a Constrained Execution Region that does defer an abort
until the end of the region. It also imposes severe restrictions on the content
of the region, including no IO.
Oct 12 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
3
by: Peter Hansen | last post by:
I'm still trying to understand the behaviour that I'm seeing but I'm already pretty sure that it's either a bug, or something that would be considered a bug if it didn't perhaps avoid even worse...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
1
by: Ray Ackley | last post by:
I'm experiencing a threading problem that's really perplexing me. I have a multithreaded application that reads car ECU information that's sent over the serial port by the ECU and received by the...
5
by: OpticTygre | last post by:
Heheh...I've got lots of questions today. If I have a loop that calls the same subroutine several times (that subroutine may be processor and network intensive): For i = 1 to 100 Call...
8
by: cj | last post by:
I need more information to read about threading in Visual Basic. Hopefully something linear w/o too many links to get lost in. I've been to...
4
by: =?Utf-8?B?aG5nbzAx?= | last post by:
All, I am developing a vb.net using threading.... I have a button to print a doc (it takes about 5-10 seconds to finish that process). As soon I click that button I start a thread and then I go...
5
by: skunkwerk | last post by:
i'm getting the wrong output for the 'title' attributes for this data. the queue holds a data structure (item name, position, and list to store results in). each thread takes in an item name and...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.