none
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.

    Questions:

    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

Answers

  • 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.

    See: http://www.shujaat.net/2012/10/weak-event-pattern-improvements-wpf-45.html

    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: http://www.codeproject.com/Articles/29922/Weak-Events-in-C

     

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


    Caillen
    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
    Moderator