Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to have only one PI instance at any point in time #2951

Merged
merged 3 commits into from
May 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions tools/PI/DevHome.PI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,35 @@ public static void Main(string[] args)

private static async Task<bool> DecideRedirection()
{
AppInstance instance;
var activatedEventArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
if (RuntimeHelper.IsCurrentProcessRunningAsAdmin())
var isElevatedInstancePresent = false;
var isUnElevatedInstancePresent = false;
var instanceList = AppInstance.GetInstances();
foreach (var appInstance in instanceList)
{
if (appInstance.Key.Equals(MainInstanceKey, StringComparison.OrdinalIgnoreCase))
{
isUnElevatedInstancePresent = true;
}
else if (appInstance.Key.Equals(ElevatedInstanceKey, StringComparison.OrdinalIgnoreCase))
{
isElevatedInstancePresent = true;
}
}

AppInstance instance;
if (isElevatedInstancePresent)
{
// Redirect to the elevated instance if present.
instance = AppInstance.FindOrRegisterForKey(ElevatedInstanceKey);
}
else if (RuntimeHelper.IsCurrentProcessRunningAsAdmin())
{
// Wait for unelevated instance to exit
var isUnElevatedInstancePresent = false;
do
while (isUnElevatedInstancePresent)
{
isUnElevatedInstancePresent = false;
var instanceList = AppInstance.GetInstances();
instanceList = AppInstance.GetInstances();
foreach (var appInstance in instanceList)
{
if (appInstance.Key.Equals(MainInstanceKey, StringComparison.OrdinalIgnoreCase))
Expand All @@ -98,7 +117,6 @@ private static async Task<bool> DecideRedirection()
}
}
}
while (isUnElevatedInstancePresent);

// Register the elevated instance key
instance = AppInstance.FindOrRegisterForKey(ElevatedInstanceKey);
Expand Down
Loading