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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:52:24+00:00 2026-05-14T07:52:24+00:00

Consider the code: class Work { public void DoStuff(string s) { Console.WriteLine(s); // ..

  • 0

Consider the code:

class Work
{
    public void DoStuff(string s)
    {
        Console.WriteLine(s);
        // .. whatever
    }
}
class Master
{
    private readonly Work work = new Work();

    public void Execute()
    {
        string hello = "hello";

        // (1) is this an ugly hack ?
        var thread1 = new Thread(new ParameterizedThreadStart(o => this.work.DoStuff((string)o)));           
        thread1.Start(hello);
        thread1.Join();

        // (2) is this similar to the one above?
        new Action<string>(s => this.work.DoStuff(s)).BeginInvoke(hello, null, null);
    }
}

Is (1) an acceptable way of easy starting some work in a seperate thread? If not a better alternative would be much appreciated.

Is (2) doing the same? I guess what I ask is if a new thread is started, or..

Hope you can help a beginner to a better understanding 🙂

/Moberg

  • 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-14T07:52:25+00:00Added an answer on May 14, 2026 at 7:52 am

    (1) is not an ugly hack, but it is not “the” way of doing threads these days. Thread Pool threads via BeginInvoke/EndInvoke, BackgroundWorker and the Task Parallel Library in .NET 4.0 are the way to go.

    (2) is good, BUT you need to pair your BeginInvoke with an EndInvoke somewhere. Assign the new Action<string> to a variable and then call x.EndInvoke() manually on it in your main thread or in a completion method (2nd parameter to BeginInvoke). See here as a decent reference.

    Edit: here’s how (2) should look to be reasonably equivalent to (1):

        var thread2 = new Action<string>(this.work.DoStuff);
        var result = thread2.BeginInvoke(hello, null, null);
        thread2.EndInvoke(result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The following code is an alternative solution which depends on… May 16, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer In oracle they are called function based indexes. For filtering… May 16, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer Putting the wild card as your first parameter in your… May 16, 2026 at 5:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Consider the following code: class Program { static void Main(string[] args) { new Program().Run(args);
Consider the following code: class Program { static void Main(string[] args) { A a
Consider the following code: public class Vehicle { public void StartEngine() { // Code
Consider the following code: class Base { void f() { } }; class Derived:
Consider the following code: namespace DisposeTest { using System; class Program { static void
I have the following code class sample { public void update(List l) { l
In following code consider the statement :- int B::*bpm; class B { public :
Consider the following code: [Authenticate(Order = 1)] public ActionResult SomeActionThatRequiresAuthentication() { var model =
Please consider this -probably poorly written- example : class Command; class Command : public
Consider this case: public Class1 { public static final String ONE = ABC; public

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.