如果出现任何通知,我必须并行观看五个日历。它工作正常,但在几次通知或一段时间后,我得到此例外“水印无效”。 我有一个我想看的邮箱列表(只有日历文件夹)。触发器每隔几秒钟启动一次,该方法会查看是否有通知。 如果我创建了一些约会,并且随时抛出“水印无效”的异常。它出现在我获得活动的Line中。
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;
}
}
}
}
答案 0 :(得分:2)
我找到了原因: 我的订阅列表不是线程安全的。 我将此添加到我的代码中,它工作正常:
lock (_subList)
{
events = p.GetEvents();
}