'VSTO addin crash Outlook
I need to loop all Outlook items and search for strings that full fill a regular expression pattern including all the attachments.
I know this is a big operation and require a lot of resources, but the project is demand to do this.
I managed to make a VSTO plugin that can do this, but the problem is that the addin cause Outlook to hang sometimes. This is not a good business solution, it is not working stable.
In my code I have make sure that I close COM object after using it.
outlookItem.Close(OlInspectorClose.olDiscard);
Marshal.ReleaseComObject(outlookItem);
The attachments are convert to steam and dispose efter using.
string AttachSchema = "http://schemas.microsoft.com/mapi/proptag/0x37010102";
byte[] filebyte = null;
PropertyAccessor pacc = attachment.PropertyAccessor;
filebyte = (byte[])pacc.GetProperty(AttachSchema);
Stream stream = new MemoryStream(filebyte);
Anyone can give some suggestions on how to make to addin stable?
Solution 1:[1]
Firstly, accessing PR_ATTACH_DATA_BIN
(or any other large PT_BINARY
properties) might not work using the PropertyAccessor
object (especially in the online mode), so you might be better off using Attachment.SaveAsFile
and then loading the file in memory (or a memory mapped file) if necessary.
Secondly, keep in mind that you can use OOM only on the primary Outlook thread. To run you code on the secondary thread, you need either Extended MAPI (C++ or Delphi only) or Redemption (I am its author - its RDO family of objects can be used on secondary threads).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |