Disabling Send / Receive, then later enabling Send / Receive, Using VSTO, in Outlook 2007 & Outlook

Dear Sir / Madam,

I have built a C# based VSTO Outlook 2007 add-in.
The function of the code is to get the details of each mail item in the inbox, and then save specific attachments to a windows folder.
It works well most of the time, but it fails if a new mail item is received while it is running.
This I think is because the references to the mail items in the object I use in the code get out of sync.
The easiest way and perhaps the only way for me to solve this issue (without completely changing the architecture of the project) is to programmaticallydisable send / receive before running the code, then re-enable send receive after running the code.
I have searched far and wide for some C# (VSTO) code to do this (e.g., disable send / receive, then re-enable send / receive, in Outlook 2007), but to no avail.
If you could show me code that does this, I would appreciate it.
Thank you,

Hello Damian,Sorry for delay. I am not sure it is related to sync of Outlook. As far as I know, there is no a way to disable receiving a mail item. However, Outlook object model exposes an SyncObject object related to this [See: SyncObject Object]. It includes the SyncStart and SyncEvent events. I think your could use SyncStart event. Code like this,        Outlook.SyncObject syncObject;        Outlook.Items items;        private void ThisAddIn_Startup(object sender, System.EventArgs e)                {            Outlook.SyncObjects syncObjects;            syncObjects=this.Application.Session.SyncObjects;            foreach(Outlook.SyncObject syn in syncObjects)            {                Debug.Print(syn.Name.ToString());            }            syncObject = this.Application.Session.SyncObjects[1];               syncObject.SyncStart += new Microsoft.Office.Interop.Outlook.SyncObjectEvents_SyncStartEventHandler(syncObject_SyncStart);            syncObject.SyncEnd += new Microsoft.Office.Interop.Outlook.SyncObjectEvents_SyncEndEventHandler(syncObject_SyncEnd);        }        void syncObject_SyncEnd()        {        }        void syncObject_SyncStart()        {        }Is the code for saving attachments included in ThisAddIn_Startup or a click event handler of a button? As you mentioned, I think you also could use the NewMailEx event [See: Application.NewMailEx Event] or ItemAdd event of Inbox folder [See: Items.ItemAdd Event]. For ItemAdd event, please refer to this thread. For NewMailEx event, code as below, Outlook.Application app;        private void ThisAddIn_Startup(object sender, System.EventArgs e)        {            app=Globals.ThisAddIn.Application;                        app.NewMailEx+=new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(app_NewMailEx);        }        void app_NewMailEx(string EntryIDCollection)        {            Outlook.MailItem mail = Application.Session.GetItemFromID(EntryIDCollection, Type.Missing) as Outlook.MailItem;            Outlook.Attachments attachments=mail.Attachments;            foreach(Outlook.Attachment attachment in attachments)            {                attachment.SaveAsFile(…);            }        }Please try this event in your side, and see if this works.If you have any further question, or I have mistaken this scenario, please feel free to follow up.Best regards,Bessie

If it’s to hard to disable the send/receive, you could try putting outlook  in offline mode during your processing.Mind you, it’s just something that came to mine, i have no experience with outlook add-ins.

none of the sync event fires!NewMail or NewMailEx does.Is there any event for Appointments not meeting requests?thanks,Guangming