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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:33:38+00:00 2026-06-13T17:33:38+00:00

I was looking at download manager type project on codeplex and came accross this

  • 0

I was looking at download manager type project on codeplex and came accross this one:
http://nthdownload.codeplex.com/

Browsing the code I ran across methods like AddDownloads, listed below:

AddDownloads starts the _downloadQueue.AddDownloads Task and continues with the viewMaintenanceTask Task. If you look at the methods and things that happen in those 2 tasks and downstream it seems like everything is synchronous.

Also reading this blog post, Synchronous tasks with Task I’m trying to understand the advantage, if any, to wrapping synchronous methods in a TaskCompletionSource. Is it because it gives the API consumer the option to start the task on a separate thread or simply because you want to consume the method as a Task. Does a synchronous method wrapped in a TaskCompletionSource benefit from and parallel processing?

private Task<QueueOperation> AddDownloads(IEnumerable<IDownload> downloads, out Task<QueueOperation> startTask)
{
    var addTask = _downloadQueue.AddDownloads(downloads, out startTask);

    // Maintain views
    var viewMaintenanceTask = addTask.ContinueWith(t =>
    {
        if (t.Exception == null)
        {
            var addedDownloads = t.Result.DownloadErrors.Where(k => k.Value == null).Select(k => k.Key).ToList();
            var activeDownloads = ActiveDownloads.ToList();
            AddToActiveDownloads(addedDownloads.Except(activeDownloads).ToList(), false);
        }
        else
        {
            // Rethrow exception, this ensures it'll bubble up to any further ContinueWith chained off this task
            throw t.Exception;
        }
        return t.Result;
    });

    return viewMaintenanceTask;
}

The example method from the blog post, wrapping a synchronous operation in a TaskCompletionSource:

var tcs = new TaskCompletionSource<object>();

try
{
    object result = model.Deserialize(stream, null, type);
    tcs.SetResult(result);
}
catch (Exception ex)
{
    tcs.SetException(ex);
}

return tcs.Task;
  • 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-06-13T17:33:39+00:00Added an answer on June 13, 2026 at 5:33 pm

    Does a synchronous method wrapped in a TaskCompletionSource benefit from and parallel processing?

    No. Creating a TaskCompletionSource does not create a new thread in any way, shape or form.

    The code you’ve given at the bottom is pretty pointless – the task will already be completed (or faulted) when the method returns. It would only be any use if you had to consume a task. I’d probably change it to:

    try
    {
        return Task.FromResult(model.Deserialize(stream, null, type));
    }
    catch (Exception ex)
    {
        // There's no Task.FromException, unfortunately.
        var tcs = new TaskCompletionSource<object>();
        tcs.SetException(ex);
        return tcs.Task;
    }
    

    In C# it’s the equivalent of writing an async method without an await expression:

    public static async Task<object> Deserialize(Model model, Stream stream,
                                                 Type type)
    {
        return model.Deserialize(stream, null, type);
    }
    

    If you want genuine parallelism, you should use Task.Run (.NET 4.5) or Task.Factory.StartNew (.NET 4).

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

Sidebar

Related Questions

I'm looking at Haacks article here - http://haacked.com/archive/2009/07/31/single-project-areas.aspx When I download the sample I
I am looking to download full Wikipedia text for my college project. Do I
I want to develop a download manager supporting segmented download. So, I am looking
I was looking to download android emulator source code and can’t seem to find
Looking for a C++ async HTTP library so I can download some zip files
I'm looking for a download manager module for Drupal. Ideally, it would give the
I'm looking for a good web based download manager open source application. Mainly a
Possible Duplicate: Where is the c++11 standard I am looking to buy/download a few
I am looking for a recommended link to download a Tortoise equivalent for OpenSUSE
Im looking for a script that will take OData feed and download some .wmv

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.