protected override void OnBackgroundActivated()

in MiddlemanElectronSampleApp/AppServiceHost/AppServiceUWP/App.xaml.cs [110:148]


        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            base.OnBackgroundActivated(args);

            IBackgroundTaskInstance taskInstance = args.TaskInstance;
            var deferral = taskInstance.GetDeferral();

            AppServiceTriggerDetails appService = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            Debug.WriteLine($"appService.CallerPackageFamilyName: {appService.CallerPackageFamilyName}");  // blank if Excel
            if ((string.IsNullOrEmpty(appService.CallerPackageFamilyName)) && (_excelConnection==null))
            {
                if (_excelConnection != null)
                {
                    ExcelResetConnection();
                }

                _excelConnection = appService.AppServiceConnection;
                _excelConnection.RequestReceived += ExcelOnAppServiceRequestReceived;
                _excelConnection.ServiceClosed += ExcelConnectionServiceConnection_ServiceClosed;
                _excelAppServiceDeferral = deferral;
                taskInstance.Canceled += ExcelOnAppServicesCanceled;

                Debug.WriteLine($"Connecting excel Service {_excelConnection.GetHashCode()} {"Excel"}");
            }
            else
            {
                if (_dataConnection != null)
                {
                    DataConnectionResetConnection();
                }
                _dataConnection = appService.AppServiceConnection;
                _dataConnection.RequestReceived += DataServiceRequestReceived;
                _dataConnection.ServiceClosed += DataServiceConnection_ServiceClosed;
                _dataConnectionDeferral = deferral;
                taskInstance.Canceled += DataOnAppServicesCanceled;

                Debug.WriteLine($"Connecting Data Service {_dataConnection.GetHashCode()} {appService.CallerPackageFamilyName}");
            }
        }