我对IMvxMessenger的这种行为感到困惑。
我在viewmodel的构造函数中看到了这样的订阅:
_updateToken = _messenger.SubscribeOnThreadPoolThread<PushNotificationReceivedMessage>(async (message) =>
{
await Reload();
}, MvxReference.Weak);
MvxMessage PushNotificationReceivedMessage发布在一个与firebase事件相关的位置:
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class PulseFirebaseMessagingService : FirebaseMessagingService
{
const string TAG = "PulseFirebaseMessagingService";
public override void OnMessageReceived(RemoteMessage remoteMessage)
{
Mvx.Resolve<IMvxMessenger>().Publish(new PushNotificationReceivedMessage(this));
}
}
我能够看到消息发布一次,但是多次调用了订阅。这是一个调用堆栈,显示了这种情况:
> 0xE in Core.ViewModels.MainViewModel.Reload at Core\ViewModels\MainViewModel.cs:157,9 C#
0x38 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Core.ViewModels.MainViewModel.<Reload>d__38> at /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316,17 C#
0x2A in Core.ViewModels.MainViewModel.Reload C#
0x15 in Core.ViewModels.MainViewModel.<-ctor<-ctor>b__37_0>d at Core\ViewModels\MainViewModel.cs:140,17 C#
0x38 in System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<Core.ViewModels.MainViewModel.<<-ctor>b__37_0>d> at /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:84,17 C#
0x31 in Core.ViewModels.MainViewModel.<.ctor>b__37_0 C#
0x11 in MvvmCross.Plugins.Messenger.Subscriptions.WeakSubscription<Core.Messages.PushNotificationReceivedMessage>. C#
任何人都可以对此有所了解吗?
谢谢