How to share object reference from one uwp application to another using shared memory?

Faisal Habib 11 Reputation points
2021-06-29T19:46:49.88+00:00

I was trying to make communications between UWP Client App and a background Service (out-of-process).

  1. ClientApp ((Universal Windows) C#)
  2. ServiceApp (Windows Runtime Component (Universal Windows)) => This is the background service

Communication has been established using app service. When I was trying to send an object from the client app to the service app, it was getting NULL in the service app.

Note: Both-sided communication needs to be established here. If an object property is changed from client app side, I want to get that from service app side. If a modification is done from service app side, I need to get that from client app side.

Now I've 2 questions.

  1. How can I share object reference between these 2 apps using shared memory?
  2. Is it possible to share object reference using "ValueSet"?

I wasn't able to find any good resources with any sample code. It would be very helpful if someone could share detailed solution.

Thanks,
Faisal

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,851 Reputation points
    2021-06-30T02:38:13.55+00:00

    Hello, Welcome to Micorosoft Q&A,

    How can I share object reference between these 2 apps using shared memory?

    Currently, UWP does not support share object with shared memory.

    Is it possible to share object reference using "ValueSet"?

    If you used AppService to implement app commination, you could send request data package with ValueSet. For more please refer document here. And this is code sample that you could refer.

      var message = new ValueSet();  
       message.Add("Command", "Item");  
       message.Add("ID", idx);  
       AppServiceResponse response = await this.inventoryService.SendMessageAsync(message);  
    

    When I was trying to send an object from the client app to the service app, it was getting NULL in the service app

    Please check if the enter point is correct in the client, such as AppServiceName , PackageFamilyName. For more please refer General app service troubleshooting part

    And you have another way to share data that use DataTransferManager , for more detail please refer Share Data document. And we also provide code sample for you.(share source and share target)


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.