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

The Archive Base Latest Questions

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

I got a code for calling async blocks. private delegate void MyDelegate(); void Async(MyDelegate

  • 0

I got a code for calling async blocks.

    private delegate void MyDelegate();
    void Async(MyDelegate t) {
        Thread thread = new Thread(new ThreadStart(t));
        thread.IsBackground = true;
        thread.Start();
    }

And then:

Async(delegate() {
    // code
});

I’m using it, but I’m sure that this is not the right way to do this. What are the problems with this method?

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

    There seems no point in declaring your own delegate, for one thing. Why not just:

    void Async(ThreadStart t) {
        Thread thread = new Thread(t);
        thread.IsBackground = true;
        thread.Start();
    }
    

    ? Personally I can’t see myself wanting to do this often enough (and with no way of finding out how the task is progressing) to warrant a separate method. If you’re using .NET 4 you should look into the Task Parallel Library, which still allows you to fire off asynchronous tasks – but in a rather more fully-featured way. (EDIT: Okay, so you can’t use that from .NET 2 – it’s worth bearing in mind for the future though.)

    You might also want to consider using the BeginInvoke method on delegates, which allows you to start them on the thread pool easily anyway – and pass arguments:

    Action<string, int> action = (name, age) => { ... };
    
    IAsyncResult result = action.BeginInvoke("Jon", 35, null);
    // Now you can use result if you want...
    

    EDIT: You’ve now said you’ll be doing this several times a second. Assuming this is a short-running task, you almost certainly should be using the thread-pool for this. As well as the example above, you can also use ThreadPool.QueueUserWorkItem to add a task to the thread pool. This will be more efficient (through thread reuse) than creating a new thread each time you have a task.

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

Sidebar

Related Questions

I've got a quite strange problem here. I'm calling some simple code via Ajax.Updater:
I've got the following code in one of my view controllers: - (void)tableView:(UITableView *)tableView
I have got a crash at calling function Clearrendertargetview(). Below is the code: HWND
I've got a scipt executing in C# using the powershell async execution code on
Is Dictionary.Add() thread safe when you only insert? I've got a code that insert
I've got code like this: Logger logger = new Logger(); System.Diagnostics.Stopwatch stopWatch = new
I've got the following code: void ReferenceManager_DoWork(object sender, DoWorkEventArgs e) { try { //
I've got code similar to the following... <p><label>Do you have buffet facilities?</label> <asp:RadioButtonList ID=blnBuffetMealFacilities:chk
I've got code similar to this: string s = CreateString(); if (s == )
I've got code like that: <ul class=gallery_demo_unstyled> <li class=active><img src='001.jpg' /></li> <li><img src='002.jpg' /></li>

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.