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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:17:52+00:00 2026-06-11T00:17:52+00:00

I am using WCF Async methods. I face issue when I try to return

  • 0

I am using WCF Async methods.

I face issue when I try to return the value of the callback function.

What are the possible methods of solution? (using .net 4.0, but not 4.5)

    public static Object LoadInfo()
    {
        var service = new SomeWcfService();
        service.BeginGetInfo(CallbackMethod, service);

        // HOW TO GET INFROMATION FROM CALLBACK??
        return INFORMATION;
    }

    private static void CallbackMethod(IAsyncResult ar)
    {
        // HOW TO PASS INFROMATION TO LoadInfo??
        var INFORMATION = (ar.AsyncState as SomeWcfService).EndGetInfo(ar);
    }

Note: All work should be asynchronously.

Thanks.

  • 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-11T00:17:54+00:00Added an answer on June 11, 2026 at 12:17 am

    Better you design to use the async pattern than fight against it.

    But, if you must access an async method synchronously, you can use a semaphore to block the calling thread until the async method returns.

    public static Object LoadInfo()
    {
        // this is our semaphore
        var blocker = new AutoResetEvent();
        object result = null;
    
        var service = new SomeWcfService();
        // use a lambda instead of a method as the callback.
        // this will result in a closure where we can access the result and blocker variables
        service.BeginGetInfo(x => 
        {
            // We are on a different thread within this lambda
            result = (x.AsyncState as SomeWcfService).EndGetInfo(ar);
            // release anybody calling blocker.WaitOne
            blocker.Set(); 
        }, service);
    
        // we are still on the original thread here, and
        // BeginGetInfo has possibly not yet executed, so we must wait until Set is called
        blocker.WaitOne(Timeout.Infinite); 
        return result;
    }
    

    This is rarely a good design choice. Aynchornous patterns are much better for responsive UI. Better to do something like this

    public void LoadInfo()
    {
        // Makes the UI show a loading indicator, blocking all actions except for CANCEL
        LoadingInfo = true;
    
        var service = new SomeWcfService();
        service.BeginGetInfo(CallbackMethod, service);
    }
    
    private void CallbackMethod(IAsyncResult ar)
    {
        // the UI is now released from loading 
        LoadingInfo = false;
        // the UI is triggered to show our data
        ViewModel.Data = (ar.AsyncState as SomeWcfService).EndGetInfo(ar);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using WCF RIA Services, how is it possible to determine if a record is
Using WCF Data Services (and the latest Entity Framework), I want to return data
I'm using WCF, SQL Server and ADO.NET. I'm looking at two implementation options for
I'm using WCF through Spring.net WCF integration link text This works relatively fine, however
has anybody experience with async WCF endpoints? I am trying to understand if using
I am using WCF REST Service (4.0) to expose JSON API ..but not getting
i am using VS2010 with jquery-1.4.1.js version and i try to access the WCF
I have an Asp.Net application that calls some WCF service using a proxy generated
I have a WCF service client implemented using the asynchronous event (using /async and
What is the advantage of writing the following WCF service operation using Async CTP?

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.