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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:13:09+00:00 2026-06-13T06:13:09+00:00

I have an VSTO application-level add-in, with my own custom task pane. I’m trying

  • 0

I have an VSTO application-level add-in, with my own custom task pane. I’m trying to intercept the SelectionChange event, and display information in my custom task pane that’s relevant to the selection. I do know how to do that synchronously.

However the process of fetching the information to display is slow, and I don’t want to block the application while I fetch the information. Furthermore, the user may change the selection several times, and I want to cancel any in-progress “fetch” operation if this happens.

I’ve tried await-ing the long-running operation, but since I don’t have a form open, there is no synchronization context in place, hence I get an InvalidOperationException (cross-thread operation not valid) as soon as I try to update the controls on my task pane.

async void Application_WindowSelectionChange(PowerPoint.Selection selection)
{
    var results = await MyLongRunningOperation(cancellationTokenSource.Token);

    myControl.Text = DescribeResults(results); // BOOM!
}

What’s the best way to overcome this? I tried doing as Stephen suggested in the link above, by putting the following at the start of the selection-changed event handler:

SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext())

That didn’t work. Suddenly all my other event handlers started erroring, saying “BeginInvoke cannot be called until the handle has been created”. I tried putting the same code at the start of every event handler, in case it was an all-or-nothing deal. That didn’t work either. Perhaps I should have created one WindowsFormsSynchronizationContext object and used it for all the handlers – but I’m aware I’m now clutching at straws.

If that doesn’t work, what other approaches should I try? Is BeginInvoke still the way to go, or can I jump over to the UI thread some other way?

  • 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-13T06:13:10+00:00Added an answer on June 13, 2026 at 6:13 am

    Suddenly all my other event handlers started erroring, saying “BeginInvoke cannot be called until the handle has been created”.

    That’s curious. I’m also grasping at straws, but try this:

    Control control = new Control();
    IntPtr handle = control.Handle;
    

    instead of calling SynchronizationContext.SetSynchronizationContext directly. You may need to do this at the beginning of each event.

    (Idea taken from this blog entry).

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

Sidebar

Related Questions

I have developed an application level add-in for Outlook targeting Outlook 2010 and .NET
We have a project for an Outlook plugin .vsto that we're trying to sign
I have written a few Excel 2003/2007 add-ins using VSTO, and I usually end
I have an VSTO (outlook-addin) application that uses Unity. It is deployed to a
I'm trying to write an Outlook 2007 VSTO add-in that lets you do some
We have a VSTO application-addin (not a document-addin) for Excel, and we want to
I have created a VSTO visual studio application in Visual Studio 2008. It's working
I have a VSTO Outlook 2007 Add-in. I have to check whether Outlook is
We have a VSTO Add in for Excel 2007. It works on all the
I have an excel 2007 Add-in built with VS2010 VSTO library. when i create

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.