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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:51:53+00:00 2026-05-14T23:51:53+00:00

I’m having a big problem when calling a web service from my WPF application.

  • 0

I’m having a big problem when calling a web service from my WPF application. The application/window locks until the process has completed. I’ve attempted to run this asynchronously but the problem still persists.

Currently, the web service call I’m making can last 45-60 seconds. It runs a process on the server to fetch a big chunk of data. As it take a little while I wanted to have a progress bar moving indeterminately for the user to see that the application hasn’t stalled or anything (you know how impatatient they get).

So:

    private void btnSelect_Click(object sender, RoutedEventArgs e)
    {
        wDrawingList = new WindowDrawingList(systemManager);

        AsyncMethodHandler caller = default(AsyncMethodHandler);

        caller = new AsyncMethodHandler(setupDrawingList);

        // open new thread with callback method 
        caller.BeginInvoke((Guid)((Button)sender).Tag, MyAsyncCallback, null);
    }

Click a button and the app will create the form that the async stuff will be posted to and set up the async stuff calling the async method.

    public bool setupDrawingList(Guid ID)
    {
        if (systemManager.set(ID))
        {
            wDrawingList.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
            {
                wDrawingList.ShowForm();
                Hide();
            }));

            return true;
        }

        return false;
    }

This is the async method. The showForm method contains the calls to setup the new form including the monster web service call

    public void MyAsyncCallback(IAsyncResult ar)
    {
        // Because you passed your original delegate in the asyncState parameter of the Begin call, you can get it back here to complete the call.
        MethodDelegate dlgt = (MethodDelegate)ar.AsyncState;

        // Complete the call.
        bool output = dlgt.EndInvoke(ar);

        try
        {
            // Retrieve the delegate. 
            AsyncResult result = (AsyncResult)ar;
            AsyncMethodHandler caller = (AsyncMethodHandler)result.AsyncDelegate;

            // Because this method is running from secondary thread it can never access ui objects because they are created 
            // on the primary thread.

            // Call EndInvoke to retrieve the results. 
            bool returnValue = caller.EndInvoke(ar);

            // Still on secondary thread, must update ui on primary thread 
            UpdateUI(returnValue == true ? "Success" : "Failed");
        }
        catch (Exception ex)
        {
            string exMessage = null;
            exMessage = "Error: " + ex.Message;
            UpdateUI(exMessage);
        }
    }

    public void UpdateUI(string outputValue)
    {
        // Get back to primary thread to update ui 
        UpdateUIHandler uiHandler = new UpdateUIHandler(UpdateUIIndicators);
        string results = outputValue;

        // Run new thread off Dispatched (primary thread) 
        this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, uiHandler, results);
    }

    public void UpdateUIIndicators(string outputValue)
    {
        // update user interface controls from primary UI thread
        sbi3.Content = "Processing Completed.";
    }

Any help or theories are appreciated. I’m at a loss.

Thanks in advance

  • 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-14T23:51:54+00:00Added an answer on May 14, 2026 at 11:51 pm

    You are invoking the method onto the GUI thread using the dispatcher. This means that even though you started off on a background thread, you are switching straight back onto the GUI thread so the GUI will not be able to respond.

    You need to let the main work happen on the background thread and then only use the dispatcher to switch to the GUI thread when you need to update the progress bar.

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

Sidebar

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.