2011-10-26 37 views
0

如果出現任何通知,我必須觀看五個日曆並行。它工作正常,但在幾次通知或一段時間後,我得到這個例外「水印無效」。 我有我想要觀看的郵箱列表(僅限日曆文件夾)。觸發器每隔幾秒鐘啓動一次,該方法會查看是否有通知。 如果我創建了幾個約會,並且任何時候拋出了「水印無效」的例外情況。它出現在我得到事件的線路中。PullNotifcation Exchange Web服務「水印無效」例外

public Notification(ExchangeService _server1, string[] _mailboxName1) 
     { 
      _server = _server1; 
      _listOfList = _listOfList1; 
      _mailboxName = _mailboxName1; 
      foreach (Mailbox m in _mailboxName) 
      { 
       FolderId _Id = new FolderId(WellKnownFolderName.Calendar, m); 
       PullSubscription pullSub = _server.SubscribeToPullNotifications(new FolderId[] { _Id }, 5, null, EventType.Copied, EventType.Created, EventType.Deleted, EventType.Modified, EventType.Moved); 
       _subList.Add(pullSub); 
      } 
      System.Timers.Timer aTimer = new System.Timers.Timer(); 
      aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); 
      AppSettingsReader config = new AppSettingsReader(); 
      int time = Convert.ToInt16(config.GetValue("TimerInterval", typeof(string))); 
      aTimer.Interval = time; 
      aTimer.Enabled = false; 
      aTimer.Start(); 

     } 
    private static void OnTimedEvent(object source, ElapsedEventArgs e) 
    { 
     Console.WriteLine("Timer"); 
     bool noteWatch = false; 
     foreach (PullSubscription p in _subList) 
     { 
      string type = null; 
      ItemId eventId = null; 
      //Exception the watermark is invalid!! 
      GetEventsResults events = p.GetEvents(); 

      foreach (ItemEvent itemEvent in events.ItemEvents) 
      { 

       switch (itemEvent.EventType) 
       { 
        case EventType.Created: 
         noteWatch = true; 
         eventId = itemEvent.ItemId; 
         type = "Created"; 
         break; 
       } 
      } 
     } 
    } 

回答

2

我找到原因: 我的訂閱列表不是線程安全的。 我將此代碼添加到我的代碼中,它工作正常:

lock (_subList) 
       { 
        events = p.GetEvents(); 
       }