我有3個問題,關於事件:我應該取消訂閱活動嗎?
- 我就應該總是退訂事件進行訂閱?
- 如果我沒有,會發生什麼?
- 在以下示例中,您將如何取消訂閱訂閱事件?
我有例如下面的代碼:
構造函數:用途:用於數據庫屬性更新
this.PropertyChanged += (o, e) =>
{
switch (e.PropertyName)
{
case "FirstName": break;
case "LastName": break;
}
};
這:用途:用於GUI結合包住模式進入的ViewModels
ObservableCollection<Period> periods = _lpRepo.GetDailyLessonPlanner(data.DailyDate);
PeriodListViewModel = new ObservableCollection<PeriodViewModel>();
foreach (Period period in periods)
{
PeriodViewModel periodViewModel = new PeriodViewModel(period,_lpRepo);
foreach (DocumentListViewModel documentListViewModel in periodViewModel.DocumentViewModelList)
{
documentListViewModel.DeleteDocumentDelegate += new Action<List<Document>>(OnDeleteDocument);
documentListViewModel.AddDocumentDelegate += new Action(OnAddDocument);
documentListViewModel.OpenDocumentDelegate += new Action<int, string>(OnOpenDocument);
}
PeriodListViewModel.Add(periodViewModel);
}
http:// stackoverflow。com/questions/1061727/is-it-bad-to-not-unregister-event-handlinglers – SwDevMan81 2010-11-13 19:00:01