none
[c++] How to know how many instances are running in a multi-instance uwp project?

    Question

  • How to know how many instances are running in a multi-instance uwp project?

    Windows::ApplicationModel::AppInstance::GetInstances::Size can get the count, but have to register an instance, in my case, cannot register, is there any other way?

    Or how to implement reference counting like AppInstance? Increments the reference count is easy, but how to decrements the reference count? An instance can be closed by the user or it can be killed by the system (eg. throw an exception).

    Sunday, February 10, 2019 3:21 PM

All replies

  • Hello,

    Currently I'm not aware of such a way you want. Why you cannot register and what function do you want to have by knowing this?

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 11, 2019 10:01 AM
    Moderator
  • I have used AppInstance for other features. I need to know the count because I need to synchronize the data between all instances. And skip data synchronization when there is only one instance.

    I have tried all the traditional methods. atexit, at_quick_exit, set_terminate, NtQueryObject...... All of this doesn't work or can't be used in a uwp project.

    • Edited by [-] Monday, February 11, 2019 12:55 PM
    Monday, February 11, 2019 12:46 PM
  • Hello,

    After consult from my internal channel. We want to get some info from you. We need to know what you mean by saying this "used AppInstance for other features". If you simply want to maintain a single data set between all instances you could probably use an app service to act as the data source and have all the instances pull the data from the background app service task.

    Best regards,

    Barry 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 21, 2019 1:44 AM
    Moderator
  • Hello,

    After consult from my internal channel. We want to get some info from you. We need to know what you mean by saying this "used AppInstance for other features". If you simply want to maintain a single data set between all instances you could probably use an app service to act as the data source and have all the instances pull the data from the background app service task.

    Best regards,

    Barry 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    I use AppInstance for file activation. And I use shared memory as a data source. But there is no need to write temporary data to shared memory when there is only one instance, just let users edit and then save it to the file, create shared memory and synchronize data is not necessary.

    My idea is to check the number of instances before each synchronization of the data, if there is only one instance, do nothing, or release the shared memory, otherwise perform data synchronization.

    • Edited by [-] Saturday, February 23, 2019 5:02 PM
    Saturday, February 23, 2019 4:50 PM