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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:43:17+00:00 2026-06-17T23:43:17+00:00

I have one doubt. I implemented my wcf 4.0 service method as shown below.

  • 0

I have one doubt. I implemented my wcf 4.0 service method as shown below.

    IAsyncResult BeginGetData(string userid, AsyncCallback cb, object asyncState)
    {
       // Here i want to call 2 different methods simultaneously of another class

       // string result1 = classA.Method1(userid);
       // string result2 = classA.Method2(userid);        

    }

How I can call 2 methods simultaneously and both result values send back to client in the same return method ? Can we do it using TPL ? In TPL, if we use Task.ContinueWith, it will run sequentially. Is there any way that run those 2 methods parallely and return the 2 results through the EndGetData method ? If Method1 is completing first, then it should wait for Method2 to complete. Or another way is to fireback each method result as and when they completed. Is this possible ? Please help and guide me.

  • 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-17T23:43:19+00:00Added an answer on June 17, 2026 at 11:43 pm

    I am not sure about the intracacies of using WCF to do all of this for you. However, here you can just use Task Parallel Library’s (TPL) ContinueWhenAll keyword:

    An example of its usage is

    Task task1 = Task.Factory.StartNew(() => Console.WriteLine("X"));
    Task task2 = Task.Factory.StartNew(() => Console.WriteLine("Y"));
    

    this fires the two task off concurrently on two seperate background thread-pool threads. You can then wait for both to finish using

    var continuation = Task.Factory.ContinueWhenAll(
        new[] { task1, task2 }, tasks => Console.WriteLine("Done!"));
    

    Or here, you could also use the WhenAll task combinator and write

    var continuation = Task.WhenAll(task1, task2)
        .ContinueWith(ant => Console.Writeline("Done!"));
    

    Example in your case of returning data from the tasks:

    Task<int> task1 = Task.Factory.StartNew<int>(() => 
        { 
            return SomeSerialMethodReturningInt32A(); 
        });
    Task<int> task2 = Task.Factory.StartNew<int>(() => 
        { 
            return SomeSerialMethodReturningInt32B(); 
        });
    

    then in the continuation (what ever method of continuation you choose), you can query the results (and remember to observe your AggregateExceptions) as follows

    var continuation = Task.Factory.ContinueWhenAll(
        new[] { task1, task2 }, tasks => 
            { 
                int i = task1.Result;
                int j = task2.Result;
                // Neglecting exception handling.
            });
    

    See this CodeProject article for a great introduction to TPL.

    I hope this helps.

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

Sidebar

Related Questions

I have one doubt in string . How can we acess the memory of
I have one doubt concerning c# method overloading and call resolution. Let's suppose I
i have one doubt,i have created new project in eclipse with android 2.3.1 and
I have one doubt regarding casting. public void Test(out T a, out T b)
In following program . I have one doubt. I have declared one global variable
I have a doubt in layouts.I have designed one layout using group layout using
I am new to opencv and I have a doubt with one of the
i have a doubt in sessionid. when user visit the site one sessionid will
I have one doubt, in my website i have to give an option for
I have a doubt about one of my book's statement. Talking about key-indexed search

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.