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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:39:04+00:00 2026-05-24T13:39:04+00:00

I am trying get my hands dirty with async CTP and I noticed that

  • 0

I am trying get my hands dirty with async CTP and I noticed that the compiler complains about the async return type. What is the problem with other types?

A simple demo

static void Main(string[] args)
{
    DoWork();
    Console.WriteLine("Returned to main");
    Console.Read();
}

// why do I need to return void, Task or Task<T> here?
// I know I can use something like Task<IEnumerable<string>>
private static async string[] DoWork()
{
    Console.WriteLine("DoWork started");
    return await Task.Factory.StartNew(
        delegate
        {
            Thread.Sleep(2000);                
            Console.WriteLine("DoWork done");
            return new List<string>();
        });        
}
  • 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-24T13:39:06+00:00Added an answer on May 24, 2026 at 1:39 pm

    On the await [consumption] side, we are flexible: we can await any type so long as it
    has the right methods.

    On the async method [production] side, we are inflexible: we are hard-coded to
    return only the Task type (or void).
    Why the inconsistency?

    1. Iterators already have this behavior…

      An iterator method (one which has a “yield” inside) is hard-coded to return either
      IEnumerable or IEnumerator.
      However, you can “foreach” over any type which has
      GetEnumerator/MoveNext/Current members.
      So Async is just following suite.

    2. A task is like a future, so it’s good to hard-code it…

      A Task is barely more than a future.
      A future is a basic fundamental part of a language/platform.
      There’s no reason for a language two have multiple copies of such a fundamental
      notion. One is enough. It’s so foundational that you might even add keywords to the
      language to deal with futures.
      Anyway, if someone has a future-like thing, or a richer notion of task, then they can
      build it out of Task or Func.
      (Our Tasks are already running. If you want to build something that’s “cold”, like F#
      asyncs or like IObservable, one which doesn’t start until you tell it – then you should
      build it out of a Func rather than out of a Task).

    3. Further subtleties

      Define this function:

      void f<T>(Func<Task<T>> f)
      

      And invoke it:

      f( () => 1 + await t )
      

      We’d like to be able to infer that T=int in this case. Such inference isn’t possible unless
      the compiler has hard-coded knowledge that the lambda it passes to “f” has type
      Task<int>.

    Source: Technical intro to the Async CTP

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

Sidebar

Related Questions

I am trying to get my hands dirty learning DDD (by developing a sample
I'm trying to get my hands dirty on Google Maps API v3. But now
just starting to get my hands dirty with the jQuery goodness and the first
I am trying to get my hands on MVC. I am from ASP.Net background.
I am trying to get my hands on learning Visual force. I have an
I'm trying to get an understanding of strace. So I figured a very hands
I am trying to get some hands-on learning of divs. I'm converting a site
After trying and failing to get my hands on a temporary Mac to develop
I am trying to get my hands on Rspec2 with Rails3 (never used rspec
I'm trying get values from a GridView using the following code: foreach (GridViewRow row

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.