Whenever we want to record using Speaker we need to communicate with desktop app, but it needs to call the below code every time when we want to access speaker code or speaker and microphone.
if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}
The above code accesses the Recorder.exe and creates a communication pipe using Appservice (com.recorder.service) to a desktop application. But whenever we launch FulltrustProcesslauncher it creates new instance for a Recorder app in task manager every time and previously created Instance is not being used and still listed under our UWP app in the Task Manager.
My question is: Is there a way wherein we can either use previously created instance of a Recorder app or we can kill the old instance whenever we create a fresh new connection to the Recorder app using OnBackgroundActivated and StartProcess() method? I noticed that in task manager both Recorder.exe has unique ID assigned. So it seems like whenever we launch FullTrustProcessLauncher a new Id is assigned to the Recorder app and it does not identify the old Recorder app.
The things that I tried are: I created one global variable and set it as 1 when I launch FullTrustProcessLauncher for the first time and next time when I try to access Recorder app I skip StartProcess() method. But this gives another issue wherein your code does not record. I also created one method in RecorderApp to Exit the Recorder app whenever I do not require it. But I get an Exception: object reference not set. In package Manifest file of a Packager project I have added a:SupportsMultipleInstances=false hoping that it will not create multiple instances but that too does not seem to work