Mutlithreading in Outlook

Add-in Express™ Support Service
That's what is more important than anything else

Mutlithreading in Outlook
 
Vladimir Chtchetkine


Guest


Hi everybody!

Pretty much generic question :-) How do I do my own multithreading in Outlook? Straight forward path has failed (just as I suspected :-) If I create my own thread (using SDK?Â?Ð?és _beginthreadex call) there are certain operations that lead to disaster :-) For instance, when I try to get Actions on a Mail item that I just created (in the context of the same thread) Outlook throws ?Â?Ð?ìUnable to install custom action?Â?Ð?í (or something similar to that) msg box and hangs.
I tried (in three different attempts) to call CoInitialize, CoInitializeEx(multithreaded) OleInitialize in the beginning of my thread execution but neither one seemed to be able to change anything.
So, HOW DO I DO multithreading in Outlook?

TIA,

Vladimir
Posted 28 Oct, 2004 09:28:34 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Vladimir,

I need some time to test it.
Posted 28 Oct, 2004 09:49:01 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Vladimir,
Could you check your code, may be there is an error there. I have just tested getting Actions object in the context of my thread and all works fine. I also filled the body of the Mail item (I've just created)with the names of actions from Actions collection.
I wrote an example in C#.
Posted 28 Oct, 2004 11:13:54 Top
Vladimir Chtchetkine


Guest


Sergey:

I've been looking through that code for quite some time now and I don't see any bugs. As soon as commented out that get_Actions line everything started to work just fine. There must be some "litte thing" that causes what I see... Well, I guess I will just deletegate that Actions job to a more appropriate place. Thanks for your help,

Vladimir
Posted 28 Oct, 2004 12:46:30 Top
Vladimir Chtchetkine


Guest


Well, sort of solved. I need some comments (I mean I would appreciate them) on the approach...
In my OnStartupComplete handler I create a (hidden) window and whenever I need to touch outlook API from an arbitrary thread (that I've created or my async events use) I send a message to that window (so, I have some messaging protocol) and in my window's message handler I actually do what I need using Outlook API. I tested on the problem that inspired initial post and it works just fine. But I wander if that's THE approach I should take. Any comments?

TIA,

Vladimir
Posted 28 Oct, 2004 15:50:02 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Vladimir,

I think this is the right approach. If you touch outlook API from your thread you may face the problem of cleaning Outlook interfaces. Your thread may get hung and you will not be able to unload Outlook. That is why I consider your approach with window's message handler to be the right one.
Posted 29 Oct, 2004 05:13:52 Top
Vladimir Chtchetkine


Guest


Sergey:

Thank you! Looks like this gonna work for me :-)
Posted 29 Oct, 2004 08:38:48 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Vladimir:

Good luck. :-)
Posted 29 Oct, 2004 09:05:45 Top