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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:11:15+00:00 2026-05-18T20:11:15+00:00

I need to get some stuff sorted out about all this async stuff. Let’s

  • 0

I need to get some stuff sorted out about all this async stuff.

Let’s say I want to load a big file. From my understanding there is a difference in just calling File.Read() and queuing this up into the thread pool or using the Begin-/EndRead API. 

As far as I know, if you use the BeginFoo/EndFoo API you are not even blocking any thread but instead the hardware will just call you back whenever it has finished it’s work. By contrast, spinning up a thread from the ThreadPool means you are at least blocking this particular thread for work that is actually not CPU related…

So far, so good.

I wonder what does the task library actually do if I use File.Read? Is it smart enough to change my code to use the BeginFoo/EndFoo API? Or will it just spin up a thread from the ThreadPool? 

If it’s really changing my code, I wonder how far will it hunt down my code to rewrite method calls?

Does that make any sense?

Help me out please!

  • 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-18T20:11:15+00:00Added an answer on May 18, 2026 at 8:11 pm

    You say you wonder if “the task library” changes your code. There are two distinct pieces – the Task Parallel Library (which is available today having shipped in .NET 4.0), and the new C# async stuff, which will ship with C# v5.

    The C# async stuff itself is split into two things: compiler features and an accompanying library. It’s not entirely clear what will be in the library when it finally ships – today, they’ve put some extension methods in there that add methods to Task and a few other existing class library types (e.g., WebClient) to make them work smoothly with the new compiler features. Some of the things in this C#-specific library that ships today may well become part of the .NET Framework Class library when C# 5 finally ships. However, it’s currently looking likely that there will also be some stuff that may not belong in the main framework class library, but some of that might move into a support DLL like the one you have to use if you want dynamic today.

    So, with that background, it should be clear that the task library will never rewrite your code, because it’s already there today, and it’s just a library.

    The compiler will rewrite your code, but it mainly does it the same way that iterators do today: it’ll take what looks like one sequential method and split it up into several methods, adding some state tracking to enable the method to pick up from where it left off.

    The compiler won’t replace a Read with a BeginRead. In fact C# 5 doesn’t even know anything about the Asynchronous Programming Model. (The APM is the official name for the BeginFoo/EndFoo pattern.) C# 5 demands a very specific pattern when using the await keyword that doesn’t look quite like any of the asynchronous patterns that are around today, which is why the async preview ships with a library that provides extension methods for Task – it adds in the methods that C#5 expects.

    (So just to be clear, C# 5 doesn’t have any special handling for Task when it comes to consuming asynchronous operations. On the contrary, the async preview has had to bolt on some additional methods to Task just to make it work. That said, C# 5 does have special handling for Task on the provider side of things – it is able to generate code that creates a new Task as the return value of an async method. But since your question is about consuming asynchronous features, that’s not directly relevant here.)

    Specifically, C#5 will expect the expression following the await keyword to evaluate to something that you can invoke a GetAwaiter method on. (It doesn’t care whether that method is provided by the object/struct the expression evaluates to, or provided by an extension method.) The thing returned by GetAwaiter must offer two methods: BeginAwait and EndAwait.

    Those are the only method calls that C# 5 will add to your code as it transforms it to support async/await. Furthermore, it won’t change any method calls already in your code – so if you already call some method, say, Read, it won’t get rid of that or replace it. It only adds to what you already wrote.

    The relationship between C# 5 the APM (Begin/EndXxx) is rather at arms length. The way you consume the APM is that you first wrap the APM work in a Task (which you can already do today in .NET 4, using the various overloads of the Task.Factory.FromAsync method), and then you rely on the extension methods that enable a Task to be consumed by the await keyword.

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

Sidebar

Related Questions

I need to get some stuff sorted out about all this async stuff. Let's
I need to get some values of HTML web page. I want only the
i have this code: def some_method(): #i need to get some attrs :( return
What's the best way to get this to work? I've tried some stuff but
Loosely related to this post , I need to get a list of all
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need to get some pictures which have a specific hashtag using PHP ?
I need to get some external data to form an output file name in
I need to get some random colors to draw a pie. My code works
I need to get some data from a column. For example I have data

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.