ItemSend stops responding

E

Eyal

Hi All,

I'm developing Outlook 2003 VSTO 2005 add-in, which intercepts each outgoing
mail using ItemSend event, and changes the subject according to the content
and messageboxes.

The add-in works fine a few times, and then stops responding (the ItemSend
event is not triggered).

I added these following lines in the finally block in the end of the
ItemSend event, and it helped a bit, but not completely:

finally
{
Outlook.Application olApp = new
Microsoft.Office.Interop.Outlook.Application();
olApp.ItemSend -= new
Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(olApp_ItemSend);
olApp.ItemSend += new
Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(olApp_ItemSend);
}

Help will be appreciated,
Eyal
 
E

Eyal

After further investigation, it seems that the problem occurs because i'm
using redemption inside the event.

I must use it. anyone got an idea?

Eyal
 
K

Ken Slovak - [MVP - Outlook]

You should not be instantiating a new Outlook.Application object inside a
VSTO addin. For one thing that object isn't trusted and for another you
should just be using the Application object from ThisAddIn.Application,
which is trusted.

If the event handler works a few times and then quits working it's usually a
matter of how and where you're declaring your event handling objects. Most
likely they are going out of scope or being garbage collected and therefore
no longer are valid.

Using Redemption shouldn't have any effect on the code working or not, I use
Redemption objects inside event handlers all the time.
 
E

Eyal

Hi Ken,

It seems that the problem was caused because i refrenced Outlook.MailItem
with and new object:
(Outlook.MailItem)olItem = (Outlook.MailItem)Item;

I removed it and refrenced only directly to Item, and now it doen't crash.

Thanks,
Eyal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top