Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 12th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is an object with an event attached and no references to it eligable for garbage collection?
  2. public void DispatchCallbackAfter(Action callback, TimeSpan period)
  3.     {
  4.         DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.Normal, AppSettings.MainWindow.Dispatcher);
  5.         timer.Tick += new EventHandler(DispatchCallback);
  6.         timer.Interval = period;
  7.         timer.Tag = new object[] {timer, callback};
  8.         timer.Start();
  9.     }
  10.  
  11.     private void DispatchCallback(object sender, EventArgs args)
  12.     {
  13.         DispatcherTimer t = (DispatcherTimer)sender;
  14.         t.Stop();
  15.         ((Action)((object[])t.Tag)[1])();
  16.     }