Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / January 2007

Tip: Looking for answers? Try searching our database.

Delete MailItem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
j - 23 Jan 2007 17:17 GMT
Hi,

While i delete  MailItem ( myMailItem.Delete() ) should i also call
ReleaseComObject,
and is it good idea to call Application.DoEvents after deleting item??

please review the code snippets:

...............
..........
............
mailItem.Delete();
Application.DoEvents();

Marshal.ReleaseComObject(mailItem);
mailItem = null;

.....................
.............................

is it  right way ???

TNX in advance;
Ken Slovak - [MVP - Outlook] - 23 Jan 2007 18:38 GMT
You should always release objects when done with them. I'd put the nulling
of the object before calling to release the COM object though. I don't see
any need for DoEvents given the code you showed.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Hi,
>
[quoted text clipped - 19 lines]
>
> TNX in advance;
j - 24 Jan 2007 06:59 GMT
Thanks for replay,

After calling to Delete() method does pointer to mailItem still
remain?,   suppose i call to Delete() in mailItem
that exists in Recycle folder.

TNX.

On Jan 23, 8:38 pm, "Ken Slovak - [MVP - Outlook]"
<kenslo...@mvps.org> wrote:
> You should always release objects when done with them. I'd put the nulling
> of the object before calling to release the COM object though. I don't see
[quoted text clipped - 29 lines]
>
> > TNX in advance;- Hide quoted text -- Show quoted text -
Ken Slovak - [MVP - Outlook] - 24 Jan 2007 15:02 GMT
If an item is deleted and you still have a reference to that item it will
point to a null object but the object still needs to be released.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Thanks for replay,
>
[quoted text clipped - 3 lines]
>
> TNX.
j - 24 Jan 2007 21:58 GMT
Thanx, great explanation.

Could u please suggest mr thr brst practise of releasing com objects in
.NET.
I develop addin for OL 2003 and using .net 2 C#. When and which objects
i should release ??

for example in newinspector event i get inspector object, after this i
perform casting to mailItem for example, and
let's say  concernig to my business logic  i should do nothing cause
this mailitem's named property is wrong or whatever, and i exit this
method (newinspector )  ,  my question is:

Do i need to release mailItem with Marshal.ReleaseComObject??  i guess
yes
and do i need to Release also inspector objec, that i get as parameter
in method?????

TNX in advance.

On Jan 24, 5:02 pm, "Ken Slovak - [MVP - Outlook]"
<kenslo...@mvps.org> wrote:
> If an item is deleted and you still have a reference to that item it will
> point to a null object but the object still needs to be released.
[quoted text clipped - 12 lines]
>
> > TNX.- Hide quoted text -- Show quoted text -
Ken Slovak - [MVP - Outlook] - 25 Jan 2007 18:47 GMT
You should always release all your objects and not just let them go out of
scope. I usually just set them to null and only call
Marshal.ReleaseComObject on objects declared at the module level and objects
being released on the close of the last Explorer, just before
OnDisconnection would fire. I then call in my teardown code to the
GC.Collect() method and wait for pending finalizers.

Some people call Marshal.ReleaseComObject every time they release an object,
but that's more performance intensive. If the code will run for a while
longer I don't do that usually.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Thanx, great explanation.
>
[quoted text clipped - 15 lines]
>
> TNX in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.