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

  • Home
  • SEARCH
  • 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 6072831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:12:12+00:00 2026-05-23T10:12:12+00:00

I keep reading code and examples of multi-threaded applications. From time to time I

  • 0

I keep reading code and examples of multi-threaded applications. From time to time I see a snippet like so:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("started");
        Go();
        Console.WriteLine("press [ENTER] to quit");
        Console.ReadLine();
    }

    private static void Go()
    {
        var thread = new Thread(DoSomething);
        thread.Start();
    }

    private static void DoSomething()
    {
        Console.WriteLine("doing something");
    }
}

And it keeps bothering me: should I keep the reference to the (foreground) thread somewhere? After all, it’s a local variable inside Go method. Hence, once the execution of Go is completed, the thread reference should be garbage-collected. So maybe, just maybe, the thread will be GCed while it’s executing?

Will the answer change if it’s a background thread?

Thanks in advance!

  • 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-23T10:12:13+00:00Added an answer on May 23, 2026 at 10:12 am

    A thread is one example of an object whose lifetime is not controlled by the garbage collector. Under the hood it is an operating system object. That’s alive as long as a thread is running code. The Thread class is just a wrapper for it. Another example is a window, it is alive as long as your code or the user doesn’t close it. Winforms doesn’t require that you hold a reference to the Form class wrapper. And you very typically don’t:

     Application.Run(new Form1());
    

    is the boiler plate code, you don’t hold a reference to the Form1 class instance anywhere.

    You can always re-create a Thread object from an existing running thread. You do so with Thread.CurrentThread. And it doesn’t have to be a thread that you created with the Thread constructor. It can be used inside a threadpool thread. Or a thread that wasn’t started by managed code. The main thread of your program would be a good example of that, it was started by Windows.

    Nevertheless, losing a reference to a thread is not good practice. It implies that you can’t check that it is still running. Which implies that you cannot stop it when it should be stopped. When the user wants to quit your program for example.

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

Sidebar

Related Questions

In my reading on dynamic and static typing, I keep coming up against the
I stumbled across the following warning when I was reading Code Like a Pythonista:
I've been reading a lot of PHP tutorials lately, and I keep seeing examples
I am reading Clean Code and having trouble figuring out how to keep some
In a node program I'm reading from a file stream with fs.createReadStream . But
I keep reading about C99 and C++11 and all these totally sweet things that
I keep reading about people who are test infected, meaning that they don't just
I keep reading about how great this new Canvas element for HTML5 is and
I keep reading that, in C, using pointer arithmetic is generally faster than subscripting
I keep reading how everyone states to return a XmlDocument when you want to

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.