Is there a problem with the MvvM-Light v3 unregister?
I am registering like this:
Messen开发者_StackOverflowger.Default.Register<DialogResponse>(this,
MessageTypesUI.YesNoQueryResponse,
AnswerResponse);
Then in "AnswerResponse"
Messenger.Default.Unregister<DialogResponse>(MessageTypesUI.YesNoQueryResponse);
Both methods execute, and AnswerResponse is called, but the second time it is called twice and the third time thrice, etc.
It acts as if my "Unregister" is being ignored.
I tried it both with Unregister() and plain old Unregister()
There was something in the release notes for V4 that made me suspect a problem with the version 3 unregister...
You should modify the call to Unregister to pass in the recipient object, not the message type:
Messenger.Default.Unregister<DialogResponse>(this);
If you look at the MVVM Light code for the messenger all unregister actions use the recipient - as internally the recipient is used for identifying which message handlers will be removed. The most basic method is Unregister(recipient)
, which de-registers all actions for a given recipient. All additional parameters allow for a more fine grained approach.
If you have multiple actions handling the same message type and you want to unregister only one of them you can use
Messenger.Unregister<DialogMessage>(recipient, action);
to only remove one of the actions.
Edit
The MVVM Light release notes for V. 4 indicate the following changes to the Messenger:
- Missing methods where added to. The IMessenger interface.
- An additional Unregister method allowing to use tokens for filtering was added.
- The Messenger.CleanupList method was made thread safe.
精彩评论