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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:05:47+00:00 2026-05-11T01:05:47+00:00

I am generally wary of implementing interfaces partially. However, IAsyncResult is a bit of

  • 0

I am generally wary of implementing interfaces partially. However, IAsyncResult is a bit of a special case, given that it supports several quite different usage patterns. How often do you use/see used the AsyncState/AsyncCallback pattern, as opposed to just calling EndInvoke, using AsyncWaitHandle, or polling IsCompleted (yuck)?

Related question: Detecting that a ThreadPool WorkItem has completed/waiting for completion.

Consider this class (very approximate, locking needed):

public class Concurrent<T> {     private ManualResetEvent _resetEvent;     private T _result;      public Concurrent(Func<T> f) {         ThreadPool.QueueUserWorkItem(_ => {                                          _result = f();                                          IsCompleted = true;                                          if (_resetEvent != null)                                              _resetEvent.Set();                                      });     }      public WaitHandle WaitHandle {         get {             if (_resetEvent == null)                 _resetEvent = new ManualResetEvent(IsCompleted);             return _resetEvent;         }      public bool IsCompleted {get; private set;}     ... 

It has WaitHandle (lazily created, just as described in IAsyncResult documentation) and IsCompleted, but I don’t see a sensible implementation for AsyncState ({return null;}?). So does it make sense for it to implement IAsyncResult? Note that Task in the Parallel Extensions library does implement IAsyncResult, but only IsCompleted is implemented implicitly.

  • 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. 2026-05-11T01:05:48+00:00Added an answer on May 11, 2026 at 1:05 am
    • In my experience, just calling EndInvoke without either waiting or being called back first is rarely useful
    • Just providing callbacks is sometimes not enough, as your clients might want to wait for multiple operations at once (WaitAny, WaitAll)
    • I’ve never polled IsCompleted, yuck indeed! So, you could save the implementation of IsCompleted, but it’s so simple that it doesn’t seem to be worth to potentially astonish your clients.

    So, a reasonable implementation for an asynchronously callable method should really provide a fully implemented IAsyncResult.

    BTW, you often don’t need to implement IAsyncResult yourself, just return what is returned by Delegate.BeginInvoke. See the implementation of System.IO.Stream.BeginRead for an example.

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

Sidebar

Related Questions

Generally, MVC frameeworks have a structure that looks something like: /models /views /controllers /utils
Generally speaking, the SQL queries that I write return unformatted data and I leave
Generally which is better to use?: case n when 'foo' result = 'bar' when
Generally, it is good practice to avoid GOTOs. Keeping that in mind I've been
Generally, I'm trying to create a PSCmdlet that takes a parameter of a type
Generally speaking, any ant task which accepts a <mapper> will also accept several tags
Generally We have some business logic that is causing a bottle neck within a
Generally if there is a property that gets/sets a value for state, I use
Generally speaking, individual JavaScript files that a page uses should be combined into a
Generally speaking a service layer is completely separate from UI interface.. However, i would

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.