Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 309989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:47:33+00:00 2026-05-12T07:47:33+00:00

A book as the following example and explains that you won’t see the line

  • 0

A book as the following example and explains that you won’t see the line “DoWork has ended”:

…because the thread was aborted
while DoWork was executing
Thread.Sleep

That makes sense, but what is odd is that if you change the first sleep to 6000 to give the DoWork thread time to get done with its 5000 sleep, then the DoWork thread will print “DoWork has ended” but this is after the DoWork thread has been aborted, so if the DoWork thread has been aborted at that point, what thread is the line that prints “DoWork has ended” running in? (it seems to be running at that point in the aborted thread)

using System;
using System.Threading;

namespace TestThreading838
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("MAIN THREAD started.");

            Thread DoWorkThread = new Thread(new ThreadStart(DoWork));

            DoWorkThread.Start();
            Thread.Sleep(1000); //if you change this to 6000 you see "DoWork has ended."

            DoWorkThread.Abort();

            Console.WriteLine("MAIN THREAD ending...");
            Thread.Sleep(6000);
            Console.WriteLine("MAIN THREAD ended.");

            Console.ReadLine();
        }

        public static void DoWork()
        {
            Console.WriteLine("DoWork is running.");
            try
            {
                Thread.Sleep(5000);
            }
            catch (ThreadAbortException ex)
            {
                Console.WriteLine("DoWork was aborted.");
            }
            finally
            {
                Console.WriteLine("DoWork cleaning up after being aborted.");
            }
            Console.WriteLine("DoWork has ended."); //never shown
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:47:33+00:00Added an answer on May 12, 2026 at 7:47 am

    If you change the first sleep to 6000, then the secondary thread finishes everything it needs to do before you abort it – it’s not really aborted, because you’ve just called Abort on a thread which was already dead. Notice that “DoWork was aborted” won’t be printed…

    Try printing out DoWorkThread.ThreadState before you call Abort – I’m pretty sure you’ll see it’s “Stopped”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Java, and the book I'm reading has the following example on cloning.
I just started learning MySQL, and the book I'm reading has the following example:
For class specific new_handler implementation, i came across the following example in book effective
I'm following the racetrack example from Jason Rudolph's book at InfoQ , using grails-1.2.1.
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
I'm following a book on c, and I come to some code that reads
In book named Using C++ by Rob McGregor there is following example of using
The following example is from the book 'Programming in Scala'. Given a class 'Rational'
i run the following example from book c++ concurrency in action, and pass function
In the book 'C++ In A Nutshell', there is the following example code std::vector<int>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.