2

I have written an outlook add-in to filter spam. The issue is that when the add-in is doing its job of processing a message, and especially with a large attachment that it is procesing / reading through, it is taking a lot of time and because of this the main outlook UI is un-responsive and users cannot do anything with the UI.

Is there an asynchrounous way of running the add-in processing, so that the outlook UI remains OK.

The add-in does a lot of things dueing its procesing of each message and hence it takes a lot of time.

4

2 回答 2

2

如果大部分时间都花在 Outlook API 上,那么创建另一个线程对您没有帮助。由于 Outlook 中的线程模型,从另一个线程访问对象模型将导致调用被编组到主线程,这意味着现在您的 UI 仍处于冻结状态并且您的后台线程处于阻塞状态。

如果大部分工作都花在不涉及 Outlook 对象模型的事情上,那么您可能会看到一个显着的改进,即分离一个单独的工作线程(或线程池)来处理您保存的附件。

于 2009-12-09T03:11:45.057 回答
0

It's just like with any other program basically. If you need to do something outside of the main thread do so (i.e. create another thread). There's no Outlook-specific API or framework, though.

You have to be extra careful about exception handling though. Unhandled exceptions escaping from a thread can have the weirdest results (though in most cases Outlook will simply crash).

Also, if at all possible you should try to avoid or at least drastically limit accessing the Outlook Object Model from within your processing thread.

Finally, another thing you should make sure of is that you explicitly call CoInitializeEx / CoUninitialize specially for your new thread if it in any way directly or indirectly uses COM-related functions.

于 2009-02-07T23:05:47.250 回答