如何取消注册一个自定义路由事件。
我有以下代码(非常标准的自定义路由事件):
现在一个类将使用以下代码订阅此事件:
当我关闭类实例时,我应该UnSubscribe事件(否则,实例将无法被垃圾收集)。
我该叫什么?我尝试了
欢迎任何帮助。提前感谢。
JM
我有以下代码(非常标准的自定义路由事件):
//Dispatch the Video Detection Movements
public delegate void MovementRoutedEventHandler( object sender
, MovementRoutedEventArgs e);
public class MovementRoutedEventArgs : RoutedEventArgs
{
private readonly DahuaDevice _device;
private readonly byte[] _canals;
private readonly DateTime _when;
public MovementRoutedEventArgs(DahuaDevice device, byte[] canals, DateTime when)
{
_device = device;
_canals = canals;
_when = when;
}
public DahuaDevice Device
{
get { return _device; }
}
public Byte[] Canals
{
get { return _canals; }
}
public DateTime When
{
get { return _when; }
}
}
public static RoutedEvent MovementEvent = EventManager.RegisterRoutedEvent(
"Movement"
, RoutingStrategy.Tunnel
, typeof(MovementRoutedEventHandler)
, typeof(Window)
);
public event RoutedEventHandler Movement
{
add { AddHandler(MovementEvent, value); }
remove { RemoveHandler(MovementEvent, value); }
}
public void RaiseMovementEvent(DahuaDevice device, byte[] canals, DateTime when)
{
RaiseEvent(new MovementRoutedEventArgs(device, canals, when)
{
RoutedEvent = MovementEvent
});
}
现在一个类将使用以下代码订阅此事件:
//Receive the Movement events
EventManager.RegisterClassHandler(
typeof(Window)
, Main.MovementEvent
, new Main.MovementRoutedEventHandler(MovementHandler));
当我关闭类实例时,我应该UnSubscribe事件(否则,实例将无法被垃圾收集)。
我该叫什么?我尝试了
RegisterClassHandler(typeof(Window), Main.MovementEvent, **null**)
但是我得到了一个异常...欢迎任何帮助。提前感谢。
JM