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 8540913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:42:22+00:00 2026-06-11T11:42:22+00:00

Suppose you have a class where you start some background thread: this class could

  • 0

Suppose you have a class where you start some background thread: this class could have a Run() method that starts up these threads, and a Stop() method that stops them properly. Some of these background threads may have been created manually, others may be managed by a Timer, which is activated when the above Run() method is invoked.

public void Run()
{
    m_ShutdownRequested = false; // shutdown flag disabled

    m_WorkerThread = new Thread(Work) { IsBackground = true };
    m_WorkerThread.Start();
    // ...
}

public void Stop()
{
    lock (m_LockInput)
    {
        m_ShutdownRequested = true; // shutdown flag enabled
        Monitor.Pulse(m_LockInput);
    }
    m_WorkerThread.Join(m_ShutdownTimeout);
}

Suppose that the Run() method is invoked when the user clicks the Run button on the UI. Similarly, the Stop() method is invoked when the user clicks the Stop button on the UI. How should these methods be implemented in order to be invoked via the UI? Should they both be asynchronous? If yes, how to deal with the possibility that some thread can not stop?

Suppose that after executing the Stop() method, some threads were not stopped. At this point, if the user click the Run button again, the instance of that class would have some threads not yet stopped. However, starting the Run() method, the previous m_WorkerThread instance is overwritten: what happens if this overwriting is performed when the thread is not yet finished?

  • 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-06-11T11:42:23+00:00Added an answer on June 11, 2026 at 11:42 am

    No overwriting of the thread occurs, you are simply creating a new instance of a variable and assigning it. The thread that was running will continue to run, but since you no longer have a reference to it, you won’t be able to get back to it. After the thread exits, the GC may cleanup up the thread instance, or it may not.

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

Sidebar

Related Questions

Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have this class: class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = foo self.attr2
Suppose I have some class which has a property actor_ of type Actor .
Suppose I have two lists of type MyCustomType , a class which could be
i have this class called MemoryManager, it is supposed to implement a simple smart
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose I have: class Foo { ... }; class Bar : public Foo {
Suppose I have class A { public: void print(){cout<<A; }}; class B: public A
Suppose I have: class Foo { public String Bar { get; set; } }
Suppose I have a class hierarchy as follow: class Vehicle; class Car extends Vehicle;

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.