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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:29:30+00:00 2026-06-13T00:29:30+00:00

I was testing delegates and ive stopped on BeginInvoke and EndInvoke. I wonder what

  • 0

I was testing delegates and ive stopped on BeginInvoke and EndInvoke. I wonder what happen in this fellowing code.

I though that the first begin invoke would terminate after the second since the second is only 2 seconds and the first one is 3 seconds. Don’t this make it like its a sync call ? Why ?

It seem the actual call is only called when EndInvoke is used.

/// <summary>
/// Démonstration d'un appel d'une méthode ASYNCRONE avec BeginInvoke() SANS rappel (Callback).
/// </summary>
public class AsyncBeginInvokeDemo
{
    // Voici la méthode délégué.
    // L'équivalent: Func<int, string> (Func<In1, ..., Out>)
    // Note: Aurait pu être également Action<int> si la méthode ne retourne pas de valeurs.
    delegate string MethodDelegate(int iCallTime, string message);

    /// <summary>
    /// Démarrer la démonstration.
    /// </summary>
    public void Start()
    {
        string strReturnedData = String.Empty;

        // Attaché la méthode au délégué.
        MethodDelegate dlgt = new MethodDelegate(this.LongRunningMethod);

        // Initié l'appel asyncrone A.
        IAsyncResult arA = dlgt.BeginInvoke(3000, "A est terminée!", null, null);

        // Initié l'appel asyncrone B.
        IAsyncResult arB = dlgt.BeginInvoke(2000, "B est terminée!", null, null);

        // Retrieve the results of the asynchronous call.
        strReturnedData = dlgt.EndInvoke(arA);
        Console.WriteLine(strReturnedData);
        strReturnedData = dlgt.EndInvoke(arB);
        Console.WriteLine(strReturnedData);
    }

    /// <summary>
    /// Il s'agit de l'opération à executé.
    /// </summary>
    /// <param name="iCallTime">Temps d'execution de l'opération. (Simulation)</param>
    /// <returns>Données par l'opération. (Simulation)</returns>
    public string LongRunningMethod(int iCallTime, string message)
    {
        // Mettre le thread en attente pendant un nombre de milliseconde x.
        Thread.Sleep(iCallTime);

        // Retourner des données.
        return message;
    }

}

This output :

A est terminée!
B est terminée!

Shouldn’t it be ?

B est terminée!
A est terminée!

  • 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-13T00:29:32+00:00Added an answer on June 13, 2026 at 12:29 am

    You’re explicitly calling EndInvoke:

    strReturnedData = dlgt.EndInvoke(arA);
    

    That will wait until the delegate has finished. Given that you’re passing in arA, it can only wait for the first delegate call to finish. It can’t possibly do anything with the second delegate call, because you’re explicitly saying that you want the results of the first delegate.

    It seem the actual call is only called when EndInvoke is used.

    No, it’s just that that’s when you block until the delegate has completed.

    If you add this code just before return message;:

    Console.WriteLine("Finished {0}", message);
    

    Then you’ll see output of:

    Finished B est terminée!
    Finished A est terminée!
    A est terminée!
    B est terminée!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Testing out someone elses code, I noticed a few JSP pages printing funky non-ASCII
Testing in various versions of Firefox new and old it seems that column-span in
In testing an app, I keep getting errors that occur sporadically on only one
I'm having difficulty testing some logic that uses notifications. I've read about enforcing that
I've a little problem with this code: This is the main method of the
I've been dealing with this issue for awhile now ( https://stackoverflow.com/questions/12982012/unit-testing-core-data-to-many-relationship ), but I've
I've always thought that it's impossible for this to be null inside instance method
I'm working with the ImageAnimator object for the first time and finding that a
I have some code that raises PropertyChanged events and I would like to be
I'm testing some code in C# from Visual Studio Express 2008: delegate void Hm(int

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.