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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:37:24+00:00 2026-06-16T01:37:24+00:00

I’m stumped and I need your help. I have a WPF application that calls

  • 0

I’m stumped and I need your help.

I have a WPF application that calls a WEBAPI using ASYNC & AWAIT and my UI is experiencing delays.

Here is the code I’m using…

HttpResponseMessage response = await WEBAPI.GetHttpClient().GetAsync("api/COStateType/GetStateTypesByCountryID/" + Constants.COUNTRY_ID_USA);  
response.EnsureSuccessStatusCode(); 
App.stateTypes = await response.Content.ReadAsAsync<List<coStateType>>(); 

The GetHttpClient code…

 public static HttpClient GetHttpClient()
    {
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(ConfigurationManager.AppSettings["ABS2.WEBAPI.Uri"]);
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        return client;
    }

Here is the main issue…

During startup I display a splash screen with moving gears (animation). After implementing the call to the WEBAPI that animation is no longer smooth. I have read that the ASYNC calls using the HttpClient cause UI blocking and figure that was what is happening to my animation.

Here is the question…

Is there anyway around this issue? I’ve tried wrapping this call within a BackgroundWorker and/or Task but neither resolved the issue. Is there another way to communicate with the WEBAPI that will NOT cause this UI blocking? An I doing something wrong?

Many, many thanks for any and all help!!!

  • 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-16T01:37:25+00:00Added an answer on June 16, 2026 at 1:37 am

    @Stef7 & @Panagiotis – You guys are right that the UI thread was blocked. I’m not sure I understand why an async call blocks the UI thread though; I’ll have to do more research.

    I had already tried a Background thread but that didn’t resolve my issue until I implemented ContinueWith on the Task.

    Thank you for your help.

    Here is the final code.

    public partial class Splash : Window
    {
        private TypeBO boType = new TypeBO();
        private Stopwatch swTotal = new Stopwatch();
        private Stopwatch swData= new Stopwatch();
    
        public Splash()
        {
            InitializeComponent();
            swTotal.Start();
        }
    
        private void GetData()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            lblMessage.Content = "Please Wait...";
            lblVersion.Content = "Version: " + assembly.GetName().Version.Major + "." + assembly.GetName().Version.Minor + "." + assembly.GetName().Version.Revision;
    
            swData.Start();
    
            var backgroundWorker = new BackgroundWorker();
            backgroundWorker.DoWork += this.OnBackgroundWorkerDoWork;
            backgroundWorker.RunWorkerCompleted += OnBackgroundWorkerRunWorkerCompleted;
            backgroundWorker.RunWorkerAsync();
        }
    
        private void OnBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            WEBAPI.GetHttpClient().GetAsync("api/COStateType/GetStateTypesByCountryID/"
                + Constants.COUNTRY_ID_USA).ContinueWith(r =>
                {
                    r.Result.EnsureSuccessStatusCode();
                    e.Result = r.Result.Content.ReadAsAsync<List<coStateType>>().Result;
                }).Wait();
    
            swData.Stop();
            System.Diagnostics.Debug.Write("Splash - DATA - Total Elapsed Time - " + swData.Elapsed + Environment.NewLine);
        }
    
        private void OnBackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            var backgroundWorker = sender as BackgroundWorker;
            backgroundWorker.DoWork -= this.OnBackgroundWorkerDoWork;
            backgroundWorker.RunWorkerCompleted -= OnBackgroundWorkerRunWorkerCompleted;
    
            App.stateTypes = e.Result as List<coStateType>;
    
            coStateType pleaseSelectStateType = new coStateType() { State_ID = 0, State_Nm = "Select One", Country_ID = 1 };
            App.stateTypes.Insert(0, pleaseSelectStateType);
    
            sbHideState.Completed += (snd, eva) =>
            {
                //Pre-Load User Controls
                Assembly assembly = this.GetType().Assembly;
                UserControl ucBHSearch = (UserControl)assembly.CreateInstance(string.Format("{0}.BHSearch", "ABS2.WPF.ADMIN.UserControls.BusinessHierarchy"));
                UserControl ucBHDetails = (UserControl)assembly.CreateInstance(string.Format("{0}.BHDetails", "ABS2.WPF.ADMIN.UserControls.BusinessHierarchy"));
                App.userControls.Add("BHD", ucBHDetails);
                App.userControls.Add("BHS", ucBHSearch);
    
                Login winLogin = new Login();
                winLogin.Show();
    
                swTotal.Stop();
                System.Diagnostics.Debug.Write("Splash - UI - Total Elapsed Time - " + swTotal.Elapsed + Environment.NewLine + Environment.NewLine);
                swTotal.Reset();
                this.Close();
            };
            sbHideState.Begin(gridSplash);
        }
    
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            lblMessage.Content = "";
            lblVersion.Content = "";
            sbDefaultState.Begin(gridSplash);
            sbRotateState.Begin(gridSplash);           
        }
    
        private void window_ContentRendered(object sender, EventArgs e)
        {
            sbShowState.Completed += (snd, eva) =>
            {
                GetData();
            };
            sbShowState.Begin(gridSplash);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.