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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:33:38+00:00 2026-06-07T08:33:38+00:00

In Silverlight app I need to run multiple async calls in parallel – they

  • 0

In Silverlight app I need to run multiple async calls in parallel – they will call server to check data, etc. My pseudo-code-setup looks like this

public interface IAsyncVerifier
{
    event EventHandler OnCompleted;

    void Verify();
}

// Subscribe to verifier completion events
foreach (var verifier in this.VerifierEngine.GetVerifiers())
{
    var asyncVerifier = verifier as IAsyncVerifier;
    if (asyncVerifier == null || !asyncVerifier.IsVerifierRunning()) continue;

    asyncVerifier.OnCompleted += (s, a) => DoWhat(); // ????????
    asyncVerifier.Verify();
}

So, in my mind I have interface common for all those tasks. Then before execution I subscribe to all of their events and … ?

I need to somehow wait for them to complete and proceed with what I’m doing. How to write remaining code properly? I see some kind of counter that I increment every time I call Verify() and decrement every time I get OnCompleted. But I don’t get whole picture on how to wrap it together so it doesn’t smell. Also, Silverlight runs those on background threads if I understand correctly (calls to WCF services)

EDIT:

I’m working with 3rd party verification engine. this.Verifier.VerifierEngine is not something I wrote. I can only add verifiers to collection. Usually they execute on main thread to validate properties, etc. My need is to create verifier that makes call back to server, hence async in Silverlight. I’m not dealing with threads manually, when I make call to service it returns on main thread so it’s fine, this part hidden from me. All I want is to be able to “wait” until all of the verifiers completed. The only way I can check right now is the way I’m doing.

Therefore my UI is quirky. User hits’ save after done modifying field and my verification starts. I check if all verifiers IsVerifierRunning and give user message that he needs to retry. I really need to be able to wait up for all to complete and then proceed.

  1. I don’t need to worry about threads unless proper solution will involve working with threads
  2. I have access to results already
  • 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-07T08:33:40+00:00Added an answer on June 7, 2026 at 8:33 am

    I too suggest using the Reactive Framework (Rx) to do what you want.

    First up you need a function that will turn IAsyncVerifier into an observable that will kick off the verification process and subscribe to the OnCompleted. Here it is:

    Func<IAsyncVerifier, IObservable<Unit>> startVerifier = av =>
        Observable.Create<Unit>(o =>
        {
            var subject = new AsyncSubject<Unit>();
            var s1 =
                Observable
                    .FromEventPattern(
                        h => av.OnCompleted += h,
                        h => av.OnCompleted -= h)
                    .Select(_ => Unit.Default)
                    .Subscribe(subject);
            var s2 = subject.Subscribe(o);
            av.Verify();
            return new CompositeDisposable(s1, s2);
        });
    

    This function uses an AsyncSubject to make sure that it captures the event firing.

    Now the query becomes quite straight forward.

    var query = (
        from av in VerifierEngine
            .GetVerifiers()
            .OfType<IAsyncVerifier>()
            .ToObservable()
        where !av.IsVerifierRunning()
        from result in startVerifier(av)
        select av)
            .ToArray();
    

    In the Rx world, since this is a SelectMany query the default is to run these on the thread pool – so it is run in parallel.

    The final .ToArray() call is a little different to the enumerable version of the function. The observable version changes an IObservable<T> (an observable that returns zero or more values) into IObservable<T[]> (an observable that returns a single array of zero or more values). In other words, this will wait until all of the verifiers are finished before returning them all.

    Now you just have to subscribe to the query and run whatever code you want to knowing that all the verifiers have completed.

    query.Subscribe(avs => DoWhat());
    

    If you want to run some code each time a verifier finishes and when all of them finish then you can take off the .ToArray() call and subscribe to the query like so:

    query.Subscribe(av => { /* Each */ }, () => { /* All */ });
    

    I hope this is all clear enough.

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

Sidebar

Related Questions

I need to convert a Silverlight App to WPF (to finally run it on
We have a Silverlight app which we wrote which calls a Silverlight-enabled data service.
I'm currently working on a Silverlight app and need to convert XML data into
I am writing a Silverlight 4 (could be 5) app that will run out
I have 2 touch enabled Canvas' in a Silverlight App. What I need to
I am doing small Silverlight app which will allow users to Create orders. I
Let me try to explain my challenge. I'm building a Silverlight app which will
I need to have yes No Cancel confirmation window in my silverlight app. I
Can i do a silverlight app without window?? I need somthing like a top
I'm building a wp7 Silverlight app. I need a list that is able to

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.