问题
I am designing an uwp app with multiple instances, I want to sync settings across all instances so that when I change a setting in one instance all the instances produce the same effect. How do I go about this??
回答1:
Create an out-of-proc appservice as explained in this article, disable multiinstance for appservice. In the appservice code along with storing the created appservice connection store a static list of all the appservice created by all the new app instance. Whenever settings is changed send response to the appservice and from the service relay that message to all other app instance stored in static list. In the app itself react to settings changes when response is recieved. Also manage/update the list when an app instance is closed.
回答2:
The right way to detect changes in settings across multiple instances is handle ApplicationData.DataChanged
event across all instances and after changing any settings execute ApplicationData.SignalDataChanged()
which will invoke ApplicationData.DataChanged
across all instances. Loading the Localsettings
when DataChanged
event is fired or storing the key of LocalSettings
changed before executing ApplicationData.SignalDataChanged()
and only reloading settings with that specific key are the ways to handle changes in LocalSettings
.
来源:https://stackoverflow.com/questions/61287741/sync-settings-and-update-changes-across-all-instances-in-multiple-instance-uwp-a