取消订阅observableCollection中的事件 [英] Unsubscribe from events in observableCollection

查看:127
本文介绍了取消订阅observableCollection中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个observableCollection类:



Lets say I have an observableCollection of classes:

CustomClassName testClass = new CustomClassName();
ObservableCollection<CustomClassName> collection = new ObservableCollection<CustomClassName>();
testClass.SomeEvent += OnSomeEvent;
collection.add(testClass);





当我将从集合中删除项目,我是否需要手动取消订阅事件(OnSomeEvent)或者我应该将其留给GC吗?

如果是 - 那么最好的方法是什么?



When I will delete items from a collection, do i need manually unsubscribe from events(OnSomeEvent) or should I leave it for a GC?
And if yes - what is the best way to do that?

推荐答案

我在stackoverflow上得到了答案。查看此链接
I have got an answer on stackoverflow. Check this link


这篇关于取消订阅observableCollection中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆