Outlook: ItemSend hangs explorer

C

Chris Koiak

Hi,

I'm trying to catch the ItemSend event for Outlook 2000 (and upwards) via a
..NET addin. This works fine when outlook is loaded and the user presses the
Send button. However if the user sends an email by selecting a file,
right-clicking and selecting Send To --> Mail recipient, I experience
problems. The email is sent correctly, the event thrown and outlook closes,
but windows explorer hangs. THe only way out of this is to kill the explorer
process!

Anyone got any ideas?

CODE:

public class Connect : Object, Extensibility.IDTExtensibility2
{
private Outlook.Application outlook;
private static JarioLogger log = null;
private object newItem = null;

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
log =
JarioLogger.getInstance(System.Reflection.MethodBase.GetCurrentMethod().Decl
aringType);
//System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
if(log.IsInfoEnabled) log.Info("<OnConnection>");
try
{
outlook = (Outlook.Application)application;

outlook.ItemSend += new
Outlook.ApplicationEvents_ItemSendEventHandler(outlook_ItemSend);

}
catch(Exception ex)
{
if(log.IsErrorEnabled) log.Error("<OnConnection>","An error occured",
ex);
}
}

public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if(log.IsDebugEnabled) log.Debug("<OnDisconnection>");
disposeObject(newItem);
disposeObject(addInObj);
disposeObject(outlook);

if(log.IsDebugEnabled) log.Debug("<OnDisconnection>","Finished");
}

public void OnAddInsUpdate(ref System.Array custom)
{
if(log.IsDebugEnabled) log.Debug("<OnAddInsUpdate>");
}

public void OnStartupComplete(ref System.Array custom)
{
if(log.IsDebugEnabled) log.Debug("<OnStartupComplete>");
}

public void OnBeginShutdown(ref System.Array custom)
{
if(log.IsDebugEnabled) log.Debug("<OnBeginShutdown>");
}

private void outlook_ItemSend(object Item, ref bool Cancel)
{
if(log.IsDebugEnabled) log.Debug("<outlook_ItemSend>");
newItem = Item;
}


private void disposeObject(object obj)
{
if(log.IsDebugEnabled) log.Debug("<disposeObject>");
try
{
// Can't dispose null objects!!
if(obj == null)
return;

// Loop until all references are removed
int count = Marshal.ReleaseComObject(obj);
while(count > 0)
{
count = Marshal.ReleaseComObject(obj);
}
}
catch(Exception ex)
{
if(log.IsErrorEnabled) log.Error("<disposeObject>", "An error occured",
ex);
}
obj = null;
}
}


Thanks
Chris Koiak
 
Joined
Mar 21, 2007
Messages
2
Reaction score
0
Never mind... I figured it out.

the addin code was making a call to m_olMailItem.GetInspector.EditorType property. For some reason, the COM addin does not release this Inspector COM object after I have referenced it when the event ends. Solution is to set a pointer to the inspector, then call the marshall.ReleaseComObject( obj ) function. So this is what my ItemSend event code looks like:

Dim m_olMailItem As Outlook.MailItem
Dim m_olInspector As Outlook.Inspector

Try
If TypeOf Item Is Outlook.MailItem Then
m_olMailItem = CType(Item, Outlook.MailItem)
m_olInspector = m_olMailItem.GetInspector
If m_olInspector.EditorType = Outlook.OlEditorType.olEditorWord Then
'Do Stuff...
End If
Marshal.ReleaseCOMObject(m_olInspector) 'Release the inspector object as soon as we're finished with it
End If
Catch ex as SystemException
Finally
Marshal.ReleaseCOMObject(m_olMailItem)
End Try
 

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