View Single Post
  #6  
Old October 1st 07, 04:29 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Direction/Help required for not to save MailItems in Sent Folder

See if Marshal.ReleaseComObject works any better. If not think about not
calling that function at all.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"PS" wrote in message
oups.com...
Ken

I was implementing the above discussed content and am getting an error
(which I believe shouldnt be the case) when working with the Mail
Close logic

In the MailItem_Send event as discussed - after setting Cancel = true
- in the end I start a timer event which lets say gets called after 3
seconds

But still get this error on
Marshal.FinalReleaseComObject(myMailItem);:

Error Text:
RaceOnRCWCleanup was detected
Message: An attempt has been made to free an RCW that is in use. The
RCW is in use on the active thread or another thread. Attempting to
free an in-use RCW can cause corruption or data loss.

Code he

private void MailItem_ItemSend(ref bool Cancel)
{
Business Logic here..

If certain business condition is true then.
Cancel = true
Then Timer Logic (which is below)
Timer delay = new Timer();
delay.Enabled = true;
delay.Interval = 10000;
delay.Tick += new EventHandler(delay_Tick);
}

void delay_Tick(object sender, EventArgs e)
{
myMailItem.Close(Ol.OlInspectorClose.olSave);
Or Even tried below:
myMailItem.Delete();
}

private void MailItem_ItemClose(ref bool Cancel)
{
try
{
//Execute cleanup only if the item has not changed, b'coz the
message box prompts users to save the message is displayed
//after this event. That message box also gives the user
the ability to cancel the event
//so we do not want to unwire the events here if the
message is "dirty"
if (this.isSent || myMailItem.Saved)
{
CleanMailItemEvents();
//Some more cleannup
}
}
}

public void CleanMailItemEvents()
{
Ol.ItemEvents_10_Event _myMailItemEvents = myMailItem as
Ol.ItemEvents_10_Event;
_myMailItemEvents.Close -= new
Ol.ItemEvents_10_CloseEventHandler(MailItem_ItemCl ose);
_myMailItemEvents.Send -= new
Ol.ItemEvents_10_SendEventHandler(MailItem_ItemSen d);
_myMailItemEvents.Forward -= new
Ol.ItemEvents_10_ForwardEventHandler(MailItem_Item Forward);
_myMailItemEvents.Reply -= new
Ol.ItemEvents_10_ReplyEventHandler(MailItem_ItemFo rward);
_myMailItemEvents.ReplyAll -= new
Ol.ItemEvents_10_ReplyAllEventHandler(MailItem_Ite mRelpyAll);
_myMailItemEvents = null;
Marshal.FinalReleaseComObject(myMailItem);
myMailItem = null;
}


Ads