views:

122

answers:

1

I wrote an addin for outlook, It will popup appointment's LastModificationTime while I click button

the button eventhandler like this

  Outlook.ApplicationClass outlook = new Outlook.ApplicationClass();
  Outlook.NameSpace ns = outlook.GetNamespace("MAPI");
  Outlook.MAPIFolder folder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
  Outlook.Items FolderItems = folder.Items;
  DateTime MyDate = DateTime.Now;
  List<Outlook.AppointmentItem> Appts = (
       from Outlook.AppointmentItem i in folder.Items
       where i.Start.Month == MyDate.Month && i.Start.Year == MyDate.Year
       select i).ToList();
  foreach (Outlook.AppointmentItem Appt in Appts)
  {
    System.Windows.Forms.MessageBox.Show(Appt.LastModificationTime.ToString());
  }

the issue is happened while I changed appointment in my mobile phone, then sync it to the outlook through exchange server

steps which makes issue:

  1. click button, get LastModificationTime as "time1"

  2. change start date as "start1" in my mobile phone, sync to outlook through exchange server

  3. click button, get LastModificationTime, still "time1"

  4. change start date as "start2" in outlook, but the appointment is still in "start1" date.

  5. restart outlook

  6. click button, get new LastModificationTime as "time2", and appointment is in "start1" date, "start2" is gone.

steps without issue

  1. click button, get LastModificationTime as "time1"

1.1. restart outlook

  1. change start date as "start1" in my mobile phone, sync to outlook through exchange server

  2. click button, get LastModificationTime, "time2"

It looks like List Appts is never been refreshed to latest value if the appointment is changed through exchange server.

Is there any solution for this issue? or other reason to make it happened?

A: 

Hi,

Not seeing you other code, but you need to remember to release the appointment objects Marshal.ReleaseComObject. Also is your client outlook in cache mode?

Marcus

76mel
Hi,Thanks, I tested Marshal.ReleaseComObject, it works!!!but another issue is out while I access appointment's recipients, it does not release object, and still give old LastModificationTime valueonly added below inside loop:if (Appt.Recipients.Count > 0){}
cipheremix
Can you explain abit more ? are you saying the Appointment won't release if you run through its Recipients ?
76mel
Yes, appointment wont be released if I use Appt.Recipients.Count.Using apptrecipents = Appt.Recipients, then apptrecipents.Count, all is fine now. Thanks.
cipheremix
yes that is the way you have to declare it and then release that.
76mel