Can I use Lambda as an EventHandler? It seems to me that the handler was correctly deleted and that the garbage collector should clean it. However, I didn’t see anyone else do it this way, so I thought it was better to double check.
At the same time, what is the best tool (preferably free) to use to check if it is garbage collection?
DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(10); EventHandler callback = null; callback = (s, e) => { timer.Stop(); timer.Tick -= callback; }; timer.Tick += callback; timer.Start();
Yes, the callback will have the right to garbage collection after the callback is made once. This is a smart way to subscribe to an event, to execute the handler only once.
, - , , callback timer, , ... ( , , ), .
callback
timer
A DispatcherTimer Dispatcher, List<DispatcherTimer> , . () , , , . , .
List<DispatcherTimer>
, . - . OOM, , , . , , 15 - . , .