0

I have a UWP app that does the recording and calling functionality. For this I have added two FullTrust Apps using Desktop bridge application. When I call just one fullTrust app everything works perfectly, but when I call two FullTrust apps by passing parameters (of the FullTrust apps to be started) the the first app that was started behaves incorrectly. For these two FullTrust apps I have used two different Appservice names declared in the Package.Manifest file of the Windows Packaging Project.

I have noticed that whenever I switch the position of the Fulltrust app call the last application that is called always remains active(has the priority of the Appservice connection) even if both has different app service names.

Here is the code I have added when user opens a page in UWP that starts Win32 app and background App

if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("Win32"); } if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("Background"); }

In the above code, the first app that is Started calls my Win32.exe and second background.exe.

How can I call these two apps independently? whenever we want to start them and close whenever required or may be in future I would like to start two apps at the same time but also I may need to close any app whenever required. Can anyone tel me how can I handle the correct communication path when calling two fullTrust apps at the same time?

Shakita
  • 99
  • 2
  • 12

1 Answers1

0

How can I call these two apps independently?

For launching multiple desktop app, we suggest to make Launcher app to manage multiple apps, then call LaunchFullTrustProcessForCurrentAppAsync(string parameterGroupId) and pass GroupId parameter. And at first we need add the group in the desktop bridge appxmanifes file.

<Extensions>
  <desktop:Extension Category="windows.fullTrustProcess" Executable="Launcher\Launcher.exe">
    <desktop:FullTrustProcess>
      <desktop:ParameterGroup GroupId="Background" Parameters="/background" />  
      <desktop:ParameterGroup GroupId="Win32" Parameters="/win32" />
    </desktop:FullTrustProcess>
  </desktop:Extension>
</Extensions>

Then use the Launcher to start all apps with parameter

static void Main(string[] args)
{
    // determine the package root, based on own location
    string result = Assembly.GetExecutingAssembly().Location;
    int index = result.LastIndexOf("\\");
    string rootPath = $"{result.Substring(0, index)}\\..\\";

    // process object to keep track of your child process
    Process newProcess = null;

    if (args.Length > 2)
    {
        // launch process based on parameter
        switch (args[2])
        {
            case "/background":
                newProcess = Process.Start(rootPath + @"FullTrust_Background\FullTrust_Background.exe");
                break;

            case "/win32":
                newProcess = Process.Start(rootPath + @"FullTrust_Win32\FullTrust_Win32.exe");
                break;             

        }
    }
}

For more detail please refer this tutorial.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • Thanks for your reply, I have similar implementation for calling multiple FullTrust Apps. But as I have mentioned I am able to call more than two apps but when I need to close the first app that was opened it does not close down but If I do the same with second app it closes down immediately. So I think the second fullTrust apps remains active or may be its connection is overwritten by the last FullTrust app being called from UWP. Note: I want these fullTrust apps to be close down whenever required. – Shakita Nov 26 '19 at 07:41
  • I tested with above code, I could close the fist app immediately. could share a demo that could repro this issue? – Nico Zhu Nov 26 '19 at 07:54
  • And you could check this [line](https://github.com/StefanWickDev/ExtensionGallery/blob/master/GlobalHotkey/HotkeyWindow/HotkeyWindow.cs#L34) that listen the UWP app's process, if it close then call `Application.Exit()` to close each launched app. – Nico Zhu Nov 26 '19 at 08:07
  • Thanks, but I cannot share my code with you as it is a vast project.. But whatever you have mentioned here I have already implemented at my end. I have a method in both apps that listen to the Service close event and run code to close the app. However, Can I request you to share any sample code (other than https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-2/ ) where you can call two FullTrust apps on load of the page and Consider you have App1 and App2 two buttons to close down the required app? – Shakita Nov 26 '19 at 09:08
  • I tested with stefanwick's code sample, And I close the app1 with `X` button in the toolbar. if you want to new demo, I could create new one and share it with github. – Nico Zhu Nov 26 '19 at 09:15
  • Ok thanks.. but I would like to mention here that, both of my FullTrust apps Communicate with UWP using methods using commands from UWP to desktop apps. There is no UI for any of these apps (So StefanWick's example is not relevant to my use case to close them directly using Close button of the desktop apps window) User can close them down whenever he does not require these apps running. Is there a way where we can pass additional information along with the method to Close correct desktop app?Close an app using parameters like how we Call using parameters to Start a particular app. – Shakita Nov 26 '19 at 09:35
  • You could store the close flag into `LocalSettings` and check them within desktop app regularly, if the value exist call app exit method. – Nico Zhu Nov 26 '19 at 09:43
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203152/discussion-between-shakita-and-nico-zhu-msft). – Shakita Nov 27 '19 at 07:25
  • Sure, You could close the app within the launcher project with same way that mentioned above. – Nico Zhu Nov 27 '19 at 09:07