VSTO Outlook add-in, does UI manipulation need to be done from main thread?

本小妞迷上赌 提交于 2019-12-25 14:04:27

问题


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.


回答1:


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




回答2:


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).



来源:https://stackoverflow.com/questions/29931477/vsto-outlook-add-in-does-ui-manipulation-need-to-be-done-from-main-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!