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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:02:13+00:00 2026-06-12T13:02:13+00:00

As I recently discovered to my cost, doing an await when there’s no synchronization

  • 0

As I recently discovered to my cost, doing an await when there’s no synchronization context may result in the code after the await being executed on a different thread.

I’m currently having problems with strange behaviour in a VSTO office add-in, which I think is possibly a result of this behaviour. When processing events raised by the Office application, there’s no synchronization context in place (unless I create a form, which will create a synchronization context).

My question is whether creating a form is the best / most efficient way to ensure that I have a synchronization context, or whether there’s a simpler way to do it.

  • 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-12T13:02:18+00:00Added an answer on June 12, 2026 at 1:02 pm

    Office apps do invoke their events in an STA context, but they do not provide an appropriate SynchronizationContext.

    The easiest way to work around this is explained on my blog in SynchronizationContext Odds and Ends, where I briefly describe a couple of miscellaneous things that I found while doing research for my article but just weren’t important enough to include. To fix this problem, at the beginning of every event, do this:

    SynchronizationContext.SetSynchronizationContext(
        new WindowsFormsSynchronizationContext());
    

    Any awaits after that should resume on the STA thread.

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

Sidebar

Related Questions

I recently discovered longlines mode in Emacs (after having been a regular user for
I recently discovered that if a UITextField is being edited in a controller that's
I recently discovered the shorthand if statement and after searching online I couldn't find
I recently discovered TempData to pass messages back to the view after processing logic
I recently discovered the Emacs code browsing package (ECB) and it seems to be
I recently discovered that rails or some other entity is messing up my code
I recently discovered the CSS code to have supported browsers print <thead> blocks at
I recently discovered Mustache, and after reading through all the documentation online, I am
I recently discovered the insertAdjacentHTML method and it's a god-send. Being such I wanted
I've recently discovered a website which does something really cool! Example: There are two

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.