Quit Problem when outlook object model was used in c#

U

Ugur KARATAS

in word application, my add in send e mail to someone with using outlook
object model.
But after sending mail Quit() method doesnt work truly. In task manager,
Outlook is still alive.
What is problem ?

[code snip]

Outlook.Application oApp = null;
oApp = new Outlook.Application();


Outlook.MailItem oMail = (Outlook.MailItem)
oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMail.To = "(e-mail address removed)"
oMail.Subject = TB_Subject.Text;
oMail.Body = TB_Introduction.Text;
oMail.Send();

oApp.Quit();
oApp = null;
GC.Collect();

[end of code snip]
 
T

Tran Gia Loc

Hello Ugur,
I think that you should use a certain method to release
oApp and oMail. (Indeed, oApp = null is not enough).
Otherwise OUTLOOK.EXE keeps staying in the Task Manager.
Tran Gia Loc.
 
T

Tom Rizzo [MSFT]

Make sure you dereference oMail and also call WaitForPendingFinalizers to
make sure the GC has collected all objects before continuning.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.



Tran Gia Loc said:
Hello Ugur,
I think that you should use a certain method to release
oApp and oMail. (Indeed, oApp = null is not enough).
Otherwise OUTLOOK.EXE keeps staying in the Task Manager.
Tran Gia Loc.
-----Original Message-----


in word application, my add in send e mail to someone with using outlook
object model.
But after sending mail Quit() method doesnt work truly. In task manager,
Outlook is still alive.
What is problem ?

[code snip]

Outlook.Application oApp = null;
oApp = new Outlook.Application();


Outlook.MailItem oMail = (Outlook.MailItem)
oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMail.To = "(e-mail address removed)"
oMail.Subject = TB_Subject.Text;
oMail.Body = TB_Introduction.Text;
oMail.Send();

oApp.Quit();
oApp = null;
GC.Collect();

[end of code snip]


.
 

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