3

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

Ramprasath Selvam
  • 3,868
  • 3
  • 25
  • 41
Shakita
  • 99
  • 2
  • 12
  • Have you looked into using the Singleton pattern for Recorder.exe? This way you would just reuse the existing instance if it's running, and create a new one if it's not. – Stefan Wick MSFT May 29 '19 at 17:56
  • Thank you Stefan, I have already implemented a Singleton Pattern in my code, and it works correctly. But Recorder.exe is generated when my code executes line: await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); i.e before I implement the Singleton Pattern in my code. I am really not sure how to cancel/exit this process from the Task manager and avoid multiple instances of Recorder.exe. – Shakita May 30 '19 at 05:54

0 Answers0