VSTO Outlook add-in, does UI manipulation need to

2019-09-11 00:43发布

I'm maintaining a VSTO add-in for Outlook, and it has a BackgroundWorker that handles syncing with a server. I want the worker to trigger user errors in the UI (changing the picture on a button, enabling a message in a settings window).

Does UI manipulation need to be done from the initial thread?

This StackOverflow answer says not, but a comment on it says so. It's for Excel, but still for a VSTO add-in. I tried and it seems to work from either thread, but there could be a race condition I haven't hit yet.

2条回答
放荡不羁爱自由
2楼-- · 2019-09-11 00:59

I completely agree with Dmitry. Office applications use the single threaded apartments. You should access the Object model on the main thread only. If you need to do some background processing you may extract the required information from Outlook objects and run a secondary thread for processing the data on the secondary thread. Or you may use a low-level API - Extended MAPI (or any other third-party wrappers around that API).

查看更多
男人必须洒脱
3楼-- · 2019-09-11 01:08

Yes, all Outlook / Office Object Model access must be done from the main thread. See VSTO with Windows Form and Worker Threads

查看更多
登录 后发表回答