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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:53:12+00:00 2026-05-21T14:53:12+00:00

Is it possible to use Async CTP to emulate continuations and tail recursion? I’m

  • 0

Is it possible to use Async CTP to emulate continuations and tail recursion?

I’m thinking something along the lines of:

async Task Loop(int count)
{
    if (count == 0)
        retrun;

    await ClearCallStack();
    //is it possible to continue here with a clean call stack?
    Loop(count -1)
}

I guess one needs a custom scheduler and such, but would it be possible?
(that is, can it be used to recurse w/o blowing the call stack)

  • 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-21T14:53:13+00:00Added an answer on May 21, 2026 at 2:53 pm

    Yes, this is entirely possible.

    In the newest Async CTP (Refresh for VS2010 SP1), there’s a “GeneralThreadAffineContext” class in the Unit Testing sample (either in VB or C#). That provides the requisite helper code for just running an async method in a general purpose thread-affine manner.

    By thread affinity, we mean that the async continuations get processed on the same context as the original thread, similarly to the behavior for WinForms/WPF, but without spinning up the real WPF or WinForms message loop.

    Task.Yield()‘s design is to defer the rest of the current method to the SynchronizationContext, so you don’t even need to write your own await ClearCallStack(). Instead, your sample will boil down to:

    async Task DoLoop(int count)
    {
        // yield first if you want to ensure your entire body is in a continuation
        // Final method will be off of Task, but you need to use TaskEx for the CTP
        await TaskEx.Yield();
    
        if (count == 0)
            return;
    
        //is it possible to continue here with a clean call stack?
        DoLoop(count -1)
    }
    
    void Loop(int count)
    {
        // This is a stub helper to make DoLoop appear synchronous. Even though
        // DoLoop is expressed recursively, no two frames of DoLoop will execute
        // their bodies simultaneously
        GeneralThreadAffineContext.Run(async () => { return DoLoop(count); });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use async image loader from this project http://open-pim.com/tmp/LazyList.zip with Gallery
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
Is it possible use a MySQL query to perform this kind of check? If
I need a control having these features: It should be possible use it in
Is possible to use ArcSDE API in .NET(C#) ? http://edndoc.esri.com/arcsde/9.2/api/capi/dbconnects/dbconnects.htm Thanks
Is it possible to use Java FutureTask with a Spring TaskExecutor to get a
Is it possible to use the .NET configuration objects to get at .config files
Is it possible to use TRY CATCH blocks in SQL Selects? For stuff similar
Is it possible to use LINQ in the express version of visual studio? I
Is it possible to use a function import in a where clause in entity

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.