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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:21:05+00:00 2026-05-27T07:21:05+00:00

I am using an asynchronous operation that completes in three steps, returning partial results

  • 0

I am using an asynchronous operation that completes in three steps, returning partial results before completion. Originally it’s using events to signal progress, and I want to wrap it properly as an awaitable operation (or a chain of them).

To be exact, it’s the PhotoCamera.CaptureImage method in Windows Phone 7, which fires events in the following order (with relevant result types):

  1. CaptureStarted, not that interesting to me
  2. CaptureThumbnailAvailable (Stream)
  3. CaptureImageAvailable (Stream)
  4. CaptureCompleted (bool)

How to wrap this? Currently I’m using a TaskCompletionSource and calling SetResult on CaptureCompleted. It does not address steps 2 and 3, the thumbnail and image becoming available. I decided to use callbacks for those instead.

My extension method (leaving out the code for brevity):

public static Task<bool> CaptureImageAsync(this PhotoCamera photoCamera,
                                           Action<Stream> thumbnailAvailableCallback,
                                           Action<Stream> imageAvailableCallback)

This doesn’t feel entirely clean, a mixture of Tasks and callbacks. I know of IProgress<T>. However, the progress values aren’t of uniform type (Stream, Stream, bool)… and wouldn’t that stretch the IProgress<T> pattern too far?

Using multiple Task<T> that are awaited in order is an option, but that supposes a specific order that I’d also have to enforce somehow. Maybe each task result could contain the “next” task as a member:

ThumbnailResult thumbnailResult = await photoCamera.CaptureImageAsync();
...
ImageResult imageResult = await thumbnailResult.NextTask;
...
bool finalResult = await imageResult.NextTask;

I still think that I’m somewhat off the mark here. Ideas?

  • 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-27T07:21:06+00:00Added an answer on May 27, 2026 at 7:21 am

    Personally i’ll create a class for it with 3 methods returning Task<T>. The caller will be able to call the 3 methods in any order he wants and it’ll always work. if GetFinalResultAsync is called first and then GetThumbnailAsync then only consequence is that the second Task<T> will aready have a result when await is used and it will return synchronously.

    var photoCapture = photoCamera.BeginCapture();
    
    var thumbnailResult = await photoCapture.GetThumbnailAsync();
    var imageResult = await photoCapture.GetImageAsync();
    var finalResult = await photoCapture.GetFinalResultAsync();
    

    To wait for everything :

    var thumbnailTask = photoCapture.GetThumbnailAsync();
    var imageTask = photoCapture.GetImageAsync();
    var finalTask = photoCapture.GetFinalResultAsync();
    
    await Task.WhenAll(thumbnailTask, imageTask, finalTask);
    DoWork(thumbnailTask.Result, imageTask.Result, finalTask.Result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asynchronous operation that for various reasons needs to be triggered using
I know that it's possible to implicitly provide asynchronous interaction using: Asynchronous Delegates Asynchronous
A winforms dialog is using BackgroundWorker to perform some asynchronous operations with significant success.
Im using asynchronous threading in my application WITH httpClient. I make a call using
I'm confused about the correct way of using asynchronous socket methods in C#. I
I am using nested Asynchronous callbacks to save my front-end data to the back-end
I want to make delete action asynchronous using AJAX, in the controller I make
Writing an asynchronous Ping using Raw Sockets in F#, to enable parallel requests using
I send asynchronous call using jQuery form plugin and in the case of success
I am trying to make asynchronous calls using xmlhttprequest object so it completely works

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.