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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:23:40+00:00 2026-05-19T10:23:40+00:00

Is there a reason to make every WCF service call Async? I was having

  • 0

Is there a reason to make every WCF service call Async?

I was having this discussion with my partner. He would like to make every WPF service call Async to avoid locking the UI (it is a desktop WPF application). I am against this idea. I do not feel an Async call is needed in most cases, and when it is needed both the RequestingClass and the DataManager should be coded specifically to handle the Async call.

My arguments for this is that is far more code to setup callbacks for everything and it is very confusing. I also think this could cause a performance decrease, although I haven’t verified this yet. His argument is that sometimes you are getting a lot of data back and it would lock up the UI, and it isn’t that much work to setup the WCF calls like this (he also doesn’t find the following code confusing).

We’ve both never worked with the WCF server before, so I thought I’d give him the benefit of doubt and ask here for some other opinions.

For example:

My Way:

public override User GetById(int id)
{
    return new User(service.GetUserById(id));
}

It locks the UI, UserDataManager, and WCF service channel until the WCF server returns with the User DataTransferObject, however it is easy to understand and quick to code. It would be used for most WCF service calls unless it actually expected a delay in getting data, in which case the DataManager would be setup to handle Async calls.

His Way:

public override void GetById(int id, Action<UserGroup> callback = null)
{
    // This is a queue of all callbacks waiting for a GetById request
    if (AddToSelectbyIdQueue(id, callback))
        return;

    // Setup Async Call
    var wrapper = new AsyncPatternWrapper<UserDTO>(
        (cb, asyncState) => server.BeginGetUserById(id, cb, asyncState),
        Global.Instance.Server.EndGetUserById);

    // Hookup Callback
    wrapper.ObserveOnDispatcher().Subscribe(GetByIdCompleted);

    // Run Async Call
    wrapper.Invoke();
}

private void GetByIdCompleted(UserDTO dto)
{
    User user = new User(dto);

    // This goes through the queue of callbacks waiting 
    // for this method to complete and executes them
    RunSelectIdCallbacks(user.UserId, user);
}

Callback queue on base class:

/// <summary>
/// Adds an item to the select queue, or a current fetch if there is one
/// </summary>
/// <param name="id">unique object identifier</param>
/// <param name="callback">callback to run</param>
/// <returns>False if it needs to be fetched, True if it is already being
/// fetched</returns>
protected virtual bool AddToSelectbyIdQueue(int id, Action<T> callback)
{
    // If the id already exists we have a fetch function already going
    if (_selectIdCallbacks.ContainsKey(id))
    {
        if(callback != null)
            _selectIdCallbacks[id].Add(callback);
        return true;
    }

    if (callback != null)
    {
        List<Action<T>> callbacks = new List<Action<T>> {callback};
        _selectIdCallbacks.Add(id, callbacks);
    }

    return false;
}

/// <summary>
/// Executes callbacks meant for that object Id and removes them from the queue
/// </summary>
/// <param name="id">unique identifier</param>
/// <param name="data">Data for the callbacks</param>
protected virtual void RunSelectIdCallbacks(int id, T data)
{
    if (_selectIdCallbacks.ContainsKey(id))
    {
        foreach (Action<T> callback in _selectIdCallbacks[id])
            callback(data);

        _selectIdCallbacks.Remove(id);
    }
}

It does not lock the UI, the DataManager, or the WCF Service Channel, however a lot of extra coding goes into it.

The AsyncPatternWrapper is in our application regardless. It is something that allows us to make Async WCF calls and subscribe a callback event

EDIT
We do have a wrapper which we can use from the UI thread to wrap any DataManager call. It executes the Synchronous method on a BackgroundWorker, and executes a callback against the results.

The majority of the extra code is to prevent locking the DataManager and the WCF Service channel.

  • 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-19T10:23:41+00:00Added an answer on May 19, 2026 at 10:23 am

    Your partner is correct; you shouldn’t block the UI thread.

    As an alternative to async calls, you can also make synchronous calls in a background thread using a BackgroundWorker or the ThreadPool.

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

Sidebar

Related Questions

Is there any reason something like this would not work? This is the logic
Is there is any reason to make the permissions on an overridden C++ virtual
Is there any real reason not to make a member function virtual in C++?
Is there any reason that will make you use: add2 = lambda n: n+2
I have a Silverlight application using a WCF service hosted in IIS. I make
I want to make a Configuration Data Manager. This would allow multiple services to
Is there any reason not to use the bitwise operators &, |, and ^
Is there any reason why I should pick JSON over XML, or vice-versa if
Is there any reason to use a varchar field instead of a date field
Is there any reason to start a GUI program (application for Windows) written in

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.