WinUI3 CommunityToolkit MVVM Messenger calling on disposed objects?

36 Views Asked by At

I am using the WeakReferenceMessenger in CommunityToolkit.MVVM in my WinUI3.

It is my understanding that by using the WeakReferenceMessager I do not need to worry about the recipient object's lifetime.

So, I have an object that is a recipient, that gets disposed. I am finding that the next time a message to which it was subscribed is sent by the messenger, my disposed object has its Receive() method called, resulting in a ObjectDisposedException and a crash.

How can I prevent this? The object in question is a UserControl-derived class, so I don't know, nor have control over, when the GC disposes of the instance.

I am using version 8.2.2. of CommunityToolkit.Mvvm

Thanks for any advice!

0

There are 0 best solutions below