public async Task <bool> updateUWP(bool request, int[] statuses, bool _Test1On, bool _Test2On, bool _Test3On) { if (canUpdateAgain) { canUpdateAgain = false; ValueSet message = new ValueSet(); if (request == false) { message.Add("content", statuses); if (connection == null) { // init connection = new AppServiceConnection(); connection.AppServiceName = "UWPSibling"; connection.PackageFamilyName = Package.Current.Id.FamilyName; connection.RequestReceived += Connection_RequestReceived; connection.ServiceClosed += Connection_ServiceClosed; // attempt connection AppServiceConnectionStatus connectionStatus = AppServiceConnectionStatus.Unknown; try { connectionStatus = await connection.OpenAsync(); } catch (InvalidOperationException) { return(false); } // if UWP isn't running if (connectionStatus == AppServiceConnectionStatus.AppUnavailable) { canUpdateAgain = true; return(false); } } AppServiceResponse serviceResponse = await connection.SendMessageAsync(message); // update local variables Test1On = _Test1On; Test2On = _Test2On; Test3On = _Test3On; } else { message.Add("request", null); if (connection == null) { // init connection = new AppServiceConnection(); connection.AppServiceName = "UWPSibling"; connection.PackageFamilyName = Package.Current.Id.FamilyName; connection.RequestReceived += Connection_RequestReceived; connection.ServiceClosed += Connection_ServiceClosed; // attempt connection AppServiceConnectionStatus connectionStatus = await connection.OpenAsync(); // if UWP isn't running if (connectionStatus == AppServiceConnectionStatus.AppUnavailable) { canUpdateAgain = true; return(false); } } AppServiceResponse serviceResponse = await connection.SendMessageAsync(message); // if UWP isn't running if (serviceResponse.Status == AppServiceResponseStatus.Failure) { return(false); } // get response if (serviceResponse.Message.ContainsKey("content")) { object newMessage = null; serviceResponse.Message.TryGetValue("content", out newMessage); // if message is an int[] if (newMessage is int[]) { // init field vars int indexInArray = 0; bool test1On = false; bool test2On = false; bool test3On = false; foreach (int trueorfalse in (int[])newMessage) { // set bool state based on index switch (indexInArray) { case 0: test1On = Convert.ToBoolean(trueorfalse); break; case 1: test2On = Convert.ToBoolean(trueorfalse); break; case 2: test3On = Convert.ToBoolean(trueorfalse); break; default: break; } indexInArray++; } mainForm.SetStatuses(test1On, test2On, test3On); // update local variables Test1On = _Test1On; Test2On = _Test2On; Test3On = _Test3On; } } } } canUpdateAgain = true; return(true); }