M
Max
I have some code that launches MS Outlook and creates a new email message then
gives control of the Outlook application to the user by displaying it on the screen.
The problem is that when the user closes the Outlook application or sends an email
the Outlook window closes but the process Outlook.exe remains in memory. I have my
code waiting for the close event from the COM and I call Quit() on the Outlook
application but Outlook.exe still hangs in memory. Can anyone tell me what I'm doing
wrong? I just want to get Outlook.exe out of the memory. Sample code is below:
private Outlook.Application m_oApp = null;
private Outlook.MailItem m_oMail = null;
private void button_Click(object sender, System.EventArgs e)
{
try
{
m_oApp = new Outlook.Application();
m_oApp.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
m_oMail = (Outlook.MailItem)m_oApp.CreateItem(Outlook.OlItemType.olMailItem);
m_oMail.Display(m_oApp);
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
Debug.WriteLine("Inspectors_NewInspector");
((Outlook.InspectorEvents_Event)Inspector).Close +=
new Outlook.InspectorEvents_CloseEventHandler(Outlook_Closed);
}
private void Outlook_Closed()
{
Debug.WriteLine("Outlook_Closed");
try
{
//m_oMail.Close(Outlook.OlInspectorClose.olPromptForSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oMail);
GC.Collect();
GC.WaitForPendingFinalizers();
m_oApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oApp);
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
finally
{
m_oMail = null;
m_oApp = null;
Debug.WriteLine("Cleaned up everything....");
}
}
gives control of the Outlook application to the user by displaying it on the screen.
The problem is that when the user closes the Outlook application or sends an email
the Outlook window closes but the process Outlook.exe remains in memory. I have my
code waiting for the close event from the COM and I call Quit() on the Outlook
application but Outlook.exe still hangs in memory. Can anyone tell me what I'm doing
wrong? I just want to get Outlook.exe out of the memory. Sample code is below:
private Outlook.Application m_oApp = null;
private Outlook.MailItem m_oMail = null;
private void button_Click(object sender, System.EventArgs e)
{
try
{
m_oApp = new Outlook.Application();
m_oApp.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
m_oMail = (Outlook.MailItem)m_oApp.CreateItem(Outlook.OlItemType.olMailItem);
m_oMail.Display(m_oApp);
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
Debug.WriteLine("Inspectors_NewInspector");
((Outlook.InspectorEvents_Event)Inspector).Close +=
new Outlook.InspectorEvents_CloseEventHandler(Outlook_Closed);
}
private void Outlook_Closed()
{
Debug.WriteLine("Outlook_Closed");
try
{
//m_oMail.Close(Outlook.OlInspectorClose.olPromptForSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oMail);
GC.Collect();
GC.WaitForPendingFinalizers();
m_oApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_oApp);
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
finally
{
m_oMail = null;
m_oApp = null;
Debug.WriteLine("Cleaned up everything....");
}
}