private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs args) { //Casting must occur from the UI thread. This dispatches the casting calls to the UI thread. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { try { rootPage.NotifyUser(string.Format("Picker DisconnectButtonClicked event fired for device '{0}'", activeDeviceInformation.Name), NotifyType.StatusMessage); // Get the DialDevice instance for the selected device DialDevice selectedDialDevice = await DialDevice.FromIdAsync(args.Device.Id); // Update the picker status picker.SetDisplayStatus(selectedDialDevice, DialDeviceDisplayStatus.Connecting); DialApp app = selectedDialDevice.GetDialApp(this.dial_appname_textbox.Text); //Get the current application state //DialAppStateDetails stateDetails = await app.GetAppStateAsync(); DialAppStopResult result = await app.StopAsync(); if (result == DialAppStopResult.Stopped) { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser("Application stopped successfully.", NotifyType.StatusMessage); picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Disconnected); activeDialDevice = null; activeDeviceInformation = null; picker.Hide(); } else { if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure) { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser(string.Format("Error occured trying to stop application. Status: '{0}'", result.ToString()), NotifyType.StatusMessage); picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Error); } else //in case of DialAppStopResult.OperationNotSupported, there is not much more you can do. You could implement your own // mechanism to stop the application on that device. { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser(string.Format("Stop is not supported by device: '{0}'", activeDeviceInformation.Name), NotifyType.ErrorMessage); activeDialDevice = null; activeDeviceInformation = null; } } } catch (Exception ex) { UnhandledExceptionPage.ShowUnhandledException(ex); } }); }
private async Task <bool> TryStopDialAppAsync(DialApp app) { bool stopped = false; //Get the current application state DialAppStateDetails stateDetails = await app.GetAppStateAsync(); switch (stateDetails.State) { case DialAppState.NetworkFailure: { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser("Network Failure while getting application state", NotifyType.ErrorMessage); break; } case DialAppState.Stopped: { stopped = true; // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser("Application was already stopped.", NotifyType.StatusMessage); break; } default: { DialAppStopResult result = await app.StopAsync(); if (result == DialAppStopResult.Stopped) { stopped = true; // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser("Application stopped successfully.", NotifyType.StatusMessage); } else { if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure) { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser(string.Format("Error occured trying to stop application. Status: '{0}'", result.ToString()), NotifyType.StatusMessage); } else //in case of DialAppStopResult.OperationNotSupported, there is not much more you can do. You could implement your own // mechanism to stop the application on that device. { stopped = true; // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser(string.Format("Stop is not supported by device: '{0}'", activeDevice.Name), NotifyType.ErrorMessage); } } break; } } return(stopped); }
private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs args) { //Casting must occur from the UI thread. This dispatches the casting calls to the UI thread. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { // The args.SelectedCastingDevice is proxied from the picker process. The picker process is // dismissmed as soon as you break into the debugger. Creating a non-proxied version // allows debugging since the proxied version stops working once the picker is dismissed. DialDevice selectedDevice = await DialDevice.FromIdAsync(args.Device.Id); // Get the DeviceInformation instance for the the selected device DeviceInformation selectedDeviceInfo = await DeviceInformation.CreateFromIdAsync(selectedDevice.Id); // Update the picker status try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Disconnecting); } catch { } DialApp app = args.Device.GetDialApp(this.dial_appname_textbox.Text); //Get the current application state DialAppStateDetails stateDetails = await app.GetAppStateAsync(); switch (stateDetails.State) { case DialAppState.NetworkFailure: { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser("Network Failure while getting application state", NotifyType.ErrorMessage); // Update the picker status try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Error); } catch { } break; } case DialAppState.Stopped: { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser("Application was already stopped.", NotifyType.StatusMessage); try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Disconnected); } catch { } break; } default: { DialAppStopResult result = await app.StopAsync(); if (result == DialAppStopResult.Stopped) { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser("Application stopped successfully.", NotifyType.StatusMessage); try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Disconnected); } catch { } } else { if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure) { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser(string.Format("Error occured trying to stop application. Status: '{0}'", result.ToString()), NotifyType.StatusMessage); try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Error); } catch { } } else //in case of DialAppStopResult.OperationNotSupported, there is not much more you can do. You could implement your own // mechanism to stop the application on that device. { // In case getting the application state failed because of a network failure, you could add retry logic rootPage.NotifyUser(string.Format("Stop is not supported by device: '{0}'", selectedDeviceInfo.Name), NotifyType.ErrorMessage); } } break; } } }); }