2019年3月16日土曜日

UWP Multi Instance support - Part 2

I have a simple sample program 'DDLG.MultiInstanceTrial' on Microsoft Store and GitHub. Let me explain the hint & tips of UWP multi instance by using this sample.



DDLG.MultiInstanceTrial - Microsoft Store
https://www.microsoft.com/en-us/p/ddlgmultiinstancetrial/9nrdjtp6bdnx

Source
https://github.com/pnp0a03/MultiInstanceTrial

This post is part 2 of the series - UWP Multi Instance Support.
UWP App の Multi Instance サポート その1(in japanese)
https://ddlgjp.blogspot.com/2018/05/uwp-app-multi-instance-1.html


Enabling


To enable the multi instance, just update your Package.appxmanifest. 1) Update the namespace at "Package" element,  and 2) Add attribute "SupportsMultipleInstances" to "Application" element.
Oh, at first, you need to use the Win10 1803 or later (and SDK).

- start - Package.appxmanifest
- end -


Behavior of Protocol Activation


If you register the app as protocol handler and the app is enabled as multi instance, the behavior is differ from the single instance. When the protocol activation happen, always new instance created. On single instance, same instance's OnActivate is called again.


Resources


It seems that each instances are running on same AppContainer. This means, each instances share the one LocalSettings/LocalFolder/Etc.
You can use my sample app to see the behavior. On the right side, you can show the image file. This file name is shared by LocalSettings, then each instances can use the same value.

Event?


In this trial, I'm using the most easiest way to share the event - ApplicationData.Current.DataChanged.

ApplicationData.DataChanged
https://docs.microsoft.com/en-us/uwp/api/windows.storage.applicationdata.datachanged

When you create or modify the applicationdata, the event signaled. You can also signal it manually.

Note - This event will be signaled with background thread. It's need to use dispatcher to use it with UI thread. You can see the sample on the source above.

Memory Mapped File


As of same app container, you can share the data by using memory mapped file. In my sample, the center pane use the one.

WinMR Environment - Desktop and MR


On WinMR enabled system, you can use both the windows desktop and WinMR 3D environment.
You can run your app on both. And, it seems that both share the same app container. By using this app, I could confirm that.


0 件のコメント:

コメントを投稿