Questions tagged [weakeventmanager]
22 questions
25
votes
2 answers
Example implementation of weak events using .NET's WeakEventManager
Is there an example implementation of weak events using .NET's WeakEventManager?
I'm trying to implement it by following the "Notes to Inheritors" in the documentation, but it is vague. For example, I can't figure out how to call…

sourcenouveau
- 29,356
- 35
- 146
- 243
6
votes
1 answer
Why WeakEventManager does not fire an event when the sender is not the nominal?
I don't like off-the-standard pattern, but I was making a quick test on my app, and I bumped against this strange behavior.
Consider a normal class exposing an event, here the very common PropertyChanged, but I think could be any other.
The…

Mario Vernari
- 6,649
- 1
- 32
- 44
6
votes
1 answer
WeakEventManager holds reference to subscriber
I have been using WeakEventManager to avoid memory leaks, and i started to overuse them.
I created extension methods for example for the INotifyPropertyChanged like:
public static void AddWeakPropertyChanged(this INotifyPropertyChanged item, Action…

MBoros
- 1,090
- 7
- 19
5
votes
1 answer
Should I use weak event listeners while listening to DependencyProperty changes?
I was looking in the framework for an implementation of WeakEventManager that listens for changes to DependencyProperties. I'm a bit confused by the fact that the only weak property change event listener I find, the PropertyChangedEventManager, is…
user1228
5
votes
2 answers
WeakEventManager & DependencyPropertyChangedEventArgs
I am wondering what might be the best way to use the WeakEventManager (4.5 is fine) together with Events offerring DependencyPropertyChangedEventArgs. These do not derive from EventArgs (for performance reasons) and therefore WeakEventManager does…

Gope
- 1,672
- 1
- 13
- 19
3
votes
1 answer
Event not found on type
I have following exception
An unhandled exception of type 'System.ArgumentException' occurred in WindowsBase.dll
Additional information: 'Event' event not found on type 'ConsoleApplication.ITest'.
in this repro:
using System.Windows; // add…

Sinatr
- 20,892
- 15
- 90
- 319
3
votes
1 answer
WeakEventManager and static event
I am trying to get used to WeakEventManager and I stumble with following:
The only difference between A and B is static, please ignore copy/paste error with nameof ;)
I found this answer regarding generics and static types, but I wonder what…

Sinatr
- 20,892
- 15
- 90
- 319
3
votes
1 answer
Using WeakEventManager in Windows.Forms application
When using weak events as described here http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!373.entry in a Windows.Forms application the WeakEventManager leaks WeakReference objects.
I think this is because without a WPF message loop the…

Henrik
- 23,186
- 6
- 42
- 92
2
votes
1 answer
Is it possible to write a class that hides the difference between adding WeakEventManager handlers and traditional ones?
I have a C# (.NET 4.6.1) project that uses a lot of events. I'm tempted to move all the event handlers to the new WeakEventManager pattern - to avoid endlessly worrying about deregistering handlers to avoid memory leaks.
However I have to do lots of…

reddal
- 353
- 2
- 8
1
vote
0 answers
WINUI 3.0 - WeakEventManager missing
I cannot find the WeakEventManger class in WINUI3.
All my WPF projects uses this in the view models when I subscribe on model events that lives longer than the ViewModel.
ViewModels with long living models must be a common thing.
E.g. a short living…

user1164920
- 51
- 3
1
vote
1 answer
How can I determine if a source is being listened to by a target when using the weak event manager
I am using the weak event manager in my WPF app to hook up a source of an event to a target, using the XXXEventManager.AddListener(source, this); call. However, I have noticed that my code sometimes hooks up the same source and target more than…

Max Palmer
- 452
- 3
- 17
1
vote
0 answers
WeakEventManager for Action<>
I know that WeakEventManager is applied for delegate:
public delegate void EventHandler(object sender, TEventArgs e);
However, I would like to use WeakEventManager for Action as below:
public class SourceEvent
{
public event…

quangdien
- 339
- 1
- 2
- 14
1
vote
1 answer
Avoiding WeakEventManager and memory leaks on short lived viewmodels
I have long living models with properties displayed using a view.
The DataContext on my view is a ViewModel with a short lifespan.
Examples include row viewmodels in lists.
To avoid memory leaks the viewmodels subscribe to models using…

Johannes
- 6,490
- 10
- 59
- 108
1
vote
1 answer
Microsoft.Win32.SystemEvents events don't work with WeakEventManager
When I do
WeakEventManager
.AddHandler(null, nameof(SystemEvents.DisplaySettingsChanged), OnDisplaySettingsChanged);
My OnDisplaySettingsChanged never gets called. However, if I instead use normal event subscribtion via…

torvin
- 6,515
- 1
- 37
- 52
1
vote
1 answer
IWeakEventListener.ReceiveWeakEvent() called multiple times when PropertyChanged(null) is called on source object
I'm using the PropertyObserver class in my code to avoid doing string comparisons in PropertyChanged event handling and factor out the handling of null or string.Empty as its argument (Which indicates that all properties of an object has…

pogosama
- 1,818
- 1
- 24
- 29