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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:03:03+00:00 2026-05-15T06:03:03+00:00

So this question is regarding the .Net IAsyncResult design pattern and the necessity of

  • 0

So this question is regarding the .Net IAsyncResult design pattern and the necessity of calling EndInvoke as covered in this question

Background

I have some code where I’m firing off potentially many asynchronous calls to a particular function and then waiting for all these calls to finish before using EndInvoke() to get back all the results.

Question 1

I don’t know whether any of the calls has encountered an exception until I call EndInvoke() and in the event that an exception occurs in one of the calls the entire method should fail and the exception gets wrapped into an API specific exception and thrown upwards.

So my first question is what’s the best way then to ensure that the remainder of the async calls get properly terminated?

Is a finally block which calls EndInvoke() on the remainder of the unterminated calls (and ignores any further exceptions) the best way to do this?

Question 2

Secondly when I first fire off all my asyc calls I then call WaitHandle.WaitAll() on the array of WaitHandle instances that I’ve got from my IAsyncResult instances. The method which is firing all these async calls has a timeout to adhere to so I provide this to the WaitAll() method. Then I test whether all the calls have completed, if not then the timeout must have been reached so the method should also fail and throw another API specific exception.

So my second question is what should I do in this case?

I need to call EndInvoke() to terminate all these async calls before I throw the error but at the same time I don’t want the code to get stuck since EndInvoke() is blocking. In theory at least if the WaitAll() call times out then all the async calls should themselves have timed out and thrown exceptions (thus completing the call) since they are also governed by a timeout but this timeout is potentially different from the main timeout

  • 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-15T06:03:03+00:00Added an answer on May 15, 2026 at 6:03 am

    I would iterate through your IAsyncResult objects, wrapping each EndInvoke in a try/catch that stores any generated exception somewhere else. Then, when you’ve called all the EndInvokes, you can see if you’ve stored any exceptions and throw an API exception if so. Something like:

    var exs = new List<Exception>();
    
    foreach (IAsyncResult iasr in asyncResults) {
        try {
            iasr.EndInvoke();
        }
        catch (Exception e) {
            exs.Add(e);
        }
    }
    
    if (exs.Count > 0) {
        throw new MyException(exs.ToReadOnly());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a very conceptual question regarding jquery. i have this fiddle http://jsfiddle.net/zvCrN/ What
I have a question regarding the design of the Date object in the .Net
I had a question regarding this matter some days ago, but I'm still wondering
Again I have a question regarding this plugin: http://t.wits.sg/2008/06/20/jquery-progress-bar-11/ What I want to achieve
This question is related to database/RDBMS where i have little knowledge regarding performance and
This question is regarding the ASP.NET webservice that i am creating using the DAL-BLL
I have the following code: http://jsfiddle.net/fCWJ5/1/ , and following doubts regarding the viewbox. body{margin:0;}
I have a question regarding the ASP.NET 3.5 Treeview and Treenodes. I'd like to
I saw there are lots of resources available on net regarding this question. I
I found this question Intensive graphics application in C# (with .NET/Mono) regarding graphics applications

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.