private async void App_LeavingBackground(object sender, LeavingBackgroundEventArgs e) { try { await relayClient.Open(); } catch (Exception ex) { // failing quietly is probably ok for now since the connection will // attempt to re-open itself again on next send. It just means // we won't be able to receive messages Debug.WriteLine("Error opening connection on startup" + ex); } }
private async void DoStuffOwlClient() { if (relayClient == null) { relayClient = new StatusRelay.RelayClient(); } OwlCommand c = new OwlCommand(); c.Command = OwlCommand.Commands.RandomFull; if (!relayClient.IsConnected) { ExceptionDispatchInfo capturedException = null; try { await relayClient.Open(); } catch (Exception ex) { capturedException = ExceptionDispatchInfo.Capture(ex); } string exMessage = String.Empty; if (capturedException != null) { //await ExceptionHandler(); //capturedException.Throw(); exMessage += capturedException.SourceException.ToString(); } if (!relayClient.IsConnected) { //deferral.Complete(); TestButton.Content = "Bad: Relay Client connection is not open -- " + DateTime.Now.ToString() + " -- Error: " + exMessage; return; } } //if we made it here, do the message await relayClient.SendOwlCommandAsync(c); }