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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:27:43+00:00 2026-06-02T21:27:43+00:00

In C# is there any difference between using a delegate to do some work

  • 0

In C# is there any difference between using a delegate to do some work asynchronously (calling BeginInvoke()) and using a ThreadPool thread as shown below

public void asynchronousWork(object num)
    {
        //asynchronous work to be done
        Console.WriteLine(num);
    }

 public void test()
    {
        Action<object> myCustomDelegate = this.asynchronousWork;
        int x = 7;

        //Using Delegate
        myCustomDelegate.BeginInvoke(7, null, null);

        //Using Threadpool
        ThreadPool.QueueUserWorkItem(new WaitCallback(asynchronousWork), 7);
        Thread.Sleep(2000);
    }

Edit:
BeginInvoke makes sure that a thread from the thread pool is used to execute the asynchronous code , so is there any difference?

  • 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-02T21:27:44+00:00Added an answer on June 2, 2026 at 9:27 pm

    Joe Duffy, in his Concurrent Programming on Windows book (page 418), says this about Delegate.BeginInvoke:

    All delegate types, by convention offer a BeginInvoke and EndInvoke method alongside the ordinary synchronous Invoke method. While this is a nice programming model feature, you should stay away from them wherever possible. The implementation uses remoting infrastructure which imposes a sizable overhead to asynchronous invocation. Queue work to the thread pool directly is often a better approach, though that means you have to co-ordinate the rendezvous logic yourself.

    EDIT: I created the following simple test of the relative overheads:

    int counter = 0;
    int iterations = 1000000;
    Action d = () => { Interlocked.Increment(ref counter); };
    
    var stopwatch = new System.Diagnostics.Stopwatch();
    stopwatch.Start();
    for (int i = 0; i < iterations; i++)
    {
        var asyncResult = d.BeginInvoke(null, null);
    }
    
    do { } while(counter < iterations);
    stopwatch.Stop();
    
    Console.WriteLine("Took {0}ms", stopwatch.ElapsedMilliseconds);
    Console.ReadLine();
    

    On my machine the above test runs in around 20 seconds. Replacing the BeginInvoke call with

    System.Threading.ThreadPool.QueueUserWorkItem(state =>
    {
        Interlocked.Increment(ref counter);
    });
    

    changes the running time to 864ms.

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

Sidebar

Related Questions

Is there any difference between using: $(document).ready(function(){ vs. $(function(){ Does one of these work
When dealing with a collection of key/value pairs is there any difference between using
Just a quick question. Is there any performance difference between using PDO::fetchAll() and PDO::fetch()
Is there really any difference between using If(this) { } Else If(that) { }
Is there any difference between using keyword unsafe before method or before block of
In javascript is there any difference between using element.style.setAttribute('width', '150px'); and element.style.width = '150px';
Is there any performance difference between using int a=a+1 and a++ in Java ?
Is there any difference between MySQL BETWEEN operator and using >= <=? When i
Is there any practical difference between a regexp using an escape character versus one
When implementing iterator using yield return , is there any difference between returning IEnumerator

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.