Messaging center is not working when object is not there in memory

This is how I am sending data from classA.
RequestClassA req= new RequestClassA
{
Id = Id
};
MessagingCenter.Send<string, RequestClassA >(nameof(classA), "FileClicked", req);
This is how I am receiving data in ClassB.
MessagingCenter.Unsubscribe<string, RequestClassA >(nameof(ClassB), "FileClicked");
MessagingCenter.Subscribe<string, RequestClassA >(nameof(ClassB), "FileClicked", (s, args) => {
Device.InvokeOnMainThreadAsync(async () =>
{
//Some Code Here
});
});

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited December 2019

    What do you mean by Messaging center is not working ?

    Error happens ? Or data not received in Class B ?

    And how you know object is not there in memory ?

  • MonalishaMonalisha Member ✭✭

    @ColeX said:
    What do you mean by Messaging center is not working ?

    Error happens ? Or data not received in Class B ?

    And how you know object is not there in memory ?

    Actually control is not coming to the below method (I put debug point).

    MessagingCenter.Unsubscribe<string, RequestClassA >(nameof(ClassB), "FileClicked");
    MessagingCenter.Subscribe<string, RequestClassA >(nameof(ClassB), "FileClicked", (s, args) => {
    Device.InvokeOnMainThreadAsync(async () =>
    {
    //Some Code Here
    });
    });

    There is no errors but data is not receiving on Class B.

Sign In or Register to comment.