A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Delete MailItem



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 23rd 07, 05:17 PM posted to microsoft.public.outlook.program_addins
j
external usenet poster
 
Posts: 109
Default Delete MailItem

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;

Ads
  #2  
Old January 23rd 07, 06:38 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Delete MailItem

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.

--
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


"j" wrote in message
oups.com...
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;


  #3  
Old January 24th 07, 06:59 AM posted to microsoft.public.outlook.program_addins
j
external usenet poster
 
Posts: 109
Default Delete MailItem


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]"
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
any need for DoEvents given the code you showed.

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

"j" wrote in ooglegroups.com...



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;- Hide quoted text -- Show quoted text -


  #4  
Old January 24th 07, 03:02 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Delete MailItem

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.

--
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


"j" wrote in message
ups.com...

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.


  #5  
Old January 24th 07, 09:58 PM posted to microsoft.public.outlook.program_addins
j
external usenet poster
 
Posts: 109
Default Delete MailItem

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]"
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.

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

"j" wrote in oglegroups.com...





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.- Hide quoted text -- Show quoted text -


  #6  
Old January 25th 07, 06:47 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Delete MailItem

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.

--
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


"j" wrote in message
oups.com...
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.


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MailItem flags Gary E. Outlook and VBA 8 January 18th 07 12:11 AM
How to Add a MailItem to a Folder Ron Outlook and VBA 2 January 10th 07 08:53 PM
MailItem Folder Path Fox via OfficeKB.com Outlook and VBA 1 July 7th 06 02:39 PM
verify and delete mailitem Joanne Outlook and VBA 8 June 13th 06 11:38 PM
How can I create a MailItem that displays like a received MailItem ? Clive Outlook - Using Forms 0 February 27th 06 04:14 PM


All times are GMT +1. The time now is 08:11 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.