
Untitled
By: a guest on
Jun 12th, 2012 | syntax:
None | size: 0.63 KB | hits: 13 | expires: Never
Is an object with an event attached and no references to it eligable for garbage collection?
public void DispatchCallbackAfter(Action callback, TimeSpan period)
{
DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.Normal, AppSettings.MainWindow.Dispatcher);
timer.Tick += new EventHandler(DispatchCallback);
timer.Interval = period;
timer.Tag = new object[] {timer, callback};
timer.Start();
}
private void DispatchCallback(object sender, EventArgs args)
{
DispatcherTimer t = (DispatcherTimer)sender;
t.Stop();
((Action)((object[])t.Tag)[1])();
}