Weak events in no-UI code RRS feed

  • Question

  • I need implementation of Weak Event Pattern in code that does not related to UI.

    I know about WeakEventManager Class , but it is contained in UI assembly (windowsbase.dll). I do not want make reference to that assembly.


    1) Why common functionality class WeakEventManager is contained in UI assembly?

    2) What is the best implementation of  Weak Event Pattern? All implementations I found use Delegate.CreateDelegate method. I do not want use it due to perfomance issues.

    Sunday, August 4, 2013 5:44 PM


  • Hi lgor,

    1) As you know, WeakEventManager is a subclass of DispatcherObject, so it can't be used on non-UI thread. Because it's designed for events in WPF to solve the memory leak problem. So it's actually not a "common functionality class", but only for UI use. It's just one of the implements of Weak Event Pattern.


    2) There're already lots of implements out there, some of them has some flows. In my opinion, the best implement is the one which suits you. You may expend Weak Event Pattern based on your own situation. Just like the WeakEventManager solves some specific problems under some circumstances. All in all, there is no "best", but "the most appropriate".

    Here is an article which I think is excellent:


    I hope you'll find some useful information. Good luck.

    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 6, 2013 5:58 AM