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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:04:07+00:00 2026-06-18T14:04:07+00:00

We have a library that is being used by WPF and/or Winforms clients. We’ve

  • 0

We have a library that is being used by WPF and/or Winforms clients.

We’ve provided an asynchronous method similar to:

Task<int> GetIntAsync()

We’ve also (unfortunately) provided a synchronous wrapper method:

int GetInt();

which essentially just calls the asynchronous method and calls .Result on its task.

We recently realized under certain circumstances some code in the GetIntAsync needs to run on the main UI thread (it needs to use a legacy COM component that is marked as “Single” Threading model (i.e. the component must run in the main STA thread not just any STA thread)

So the problem is that when GetInt() is called on the main thread, it will deadlock since

  • the .Result blocks the main thread,
  • the code within GetIntAsync() uses Dispatcher.Invoke to attempt to run on the main thread.

The synchronous method is already being consumed so it would be a breaking change to remove it. So instead, we’ve opted for using the WaitWithPumping in our synchronous GetInt() method to allow the invoking to the main thread to work.

This works fine except for clients that use GetInt() from their UI code. Previously, they expected that using GetInt() would leave their UI unresponsive–that is, if they called GetInt() from within a button’s click event handler, they would expect that no windows messages were processed until the handler returned. Now that messages are pumped, their UI is responsive and that same button can be clicked again (and they probably didn’t code their handler to be re-entrant).

If there is a reasonable solution, we’d like to not have our clients need to code against the UI being responsive during a call to GetInt

Question:

  • Is there a way to do a WaitWithPumping that will pump “Invoke to main” messages, but not pump other UI related messages?
  • It would suffice for our purposes if the client UI behaved as if a modal dialog were currently shown, albeit hidden (i.e. user couldn’t access the other windows). But, from what I read, you cannot hide a modal dialog.
  • Other workarounds you can think of would be appreciated.
  • 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-18T14:04:08+00:00Added an answer on June 18, 2026 at 2:04 pm

    Rather than utilizing the existing message pump you can create your own message pump within the context of GetInt. Here is a blog entry discussing how to write one. This is the full solution the blog creates.

    Using that you can write it as:

    public int GetInt()
    {
        return AsyncPump.Run(() => GetIntAsync());
    }
    

    That will result in completely blocking the UI thread as expected, while still ensuring that all continuations called from GetIntAsync don’t deadlock as they’ll be marshaled to a different SynchronizationContext. Also note that this message pump is still running on the main STA/UI thread.

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

Sidebar

Related Questions

I have a Silverlight Class Library that is being used by both Silverlight application
I have a WPF Control Library that is being added to a windows forms
I have a class library which is being used by another project, it is
I have found an image format that is being used by some applets. but
I have developed a library that is being consumed by an add-in architecture in
I have a library that interacts with our phone system, ie, Hey phone, call
I have a library that does I/O. There are a couple of external knobs
I have a library that I created with some business logic that includes writing
I have a library that has several options defined as this: #define shouldShowToolbar YES
Common scenario: I have a library that uses other libraries. For example, a math

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.