public AppModel() { var controller = new Controller(); var listener = new FrameListener(); controller.AddListener(listener); AppDomain.CurrentDomain.ProcessExit += (o, e) => { controller.RemoveListener(listener); listener.Dispose(); controller.Dispose(); }; listener.FrameArrived += listener_FrameArrived; }