void IPlatformAppLauncher.SetupForDebugging(out LaunchOptions result) { if (_launchOptions == null) { Debug.Fail("Why is SetupForDebugging being called before ParseLaunchOptions?"); throw new InvalidOperationException(); } ManualResetEvent doneEvent = new ManualResetEvent(false); var cancellationTokenSource = new CancellationTokenSource(); ExceptionDispatchInfo exceptionDispatchInfo = null; LaunchOptions localLaunchOptions = null; _waitLoop = new HostWaitLoop(LauncherResources.WaitDialogText); // Do the work on a worker thread to avoid blocking the UI. Use ThreadPool.QueueUserWorkItem instead // of Task.Run to avoid needing to unwrap the AggregateException. ThreadPool.QueueUserWorkItem((object o) => { string launchErrorTelemetryResult = null; try { localLaunchOptions = SetupForDebuggingWorker(cancellationTokenSource.Token); launchErrorTelemetryResult = "None"; } catch (Exception e) { exceptionDispatchInfo = ExceptionDispatchInfo.Capture(e); if (!(e is OperationCanceledException)) { launchErrorTelemetryResult = Telemetry.GetLaunchErrorResultValue(e); } } doneEvent.Set(); if (launchErrorTelemetryResult != null) { Telemetry.SendLaunchError(launchErrorTelemetryResult, _targetEngine.ToString()); } } ); _waitLoop.Wait(doneEvent, cancellationTokenSource); if (exceptionDispatchInfo != null) { exceptionDispatchInfo.Throw(); } if (localLaunchOptions == null) { Debug.Fail("No result provided? Should be impossible."); throw new InvalidOperationException(); } result = localLaunchOptions; }
private bool TrySetOperationInternalWithProgress(AsyncProgressOperation op, string text, CancellationTokenSource canTokenSource) { var waitLoop = new HostWaitLoop(text); lock (_eventLock) { if (_isClosed) throw new ObjectDisposedException("WorkerThread"); if (_runningOp == null) { _runningOpCompleteEvent.Reset(); OperationDescriptor runningOp = new OperationDescriptor(new AsyncOperation(() => { return op(waitLoop); })); _runningOp = runningOp; _opSet.Set(); waitLoop.Wait(_runningOpCompleteEvent, canTokenSource); Debug.Assert(runningOp.IsComplete, "Why isn't the running op complete?"); if (runningOp.ExceptionDispatchInfo != null) { runningOp.ExceptionDispatchInfo.Throw(); } return true; } } return false; }
private HttpResponseMessage CallVcRemote(Uri endpoint, string waitLoopMessage, out string responseBody) { ManualResetEvent doneEvent = new ManualResetEvent(false); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); var waitLoop = new HostWaitLoop(waitLoopMessage); ExceptionDispatchInfo exceptionDispatchInfo = null; HttpResponseMessage response = null; string content = null; ThreadPool.QueueUserWorkItem(async (object o) => { string failureCode = Telemetry.VcRemoteFailureCode.VcRemoteSucces.ToString(); try { response = await this.GetAsync(endpoint, cancellationTokenSource.Token); response.EnsureSuccessStatusCode(); content = await response.Content.ReadAsStringAsync(); } catch (HttpRequestException) { if (response != null) { if (response.StatusCode == HttpStatusCode.Unauthorized) { exceptionDispatchInfo = ExceptionDispatchInfo.Capture(new LauncherException(LauncherResources.Error_Unauthorized)); failureCode = Telemetry.VcRemoteFailureCode.VcRemoteUnauthorized.ToString(); } else { exceptionDispatchInfo = ExceptionDispatchInfo.Capture(new LauncherException(string.Format(LauncherResources.Error_VcRemoteUnknown, response.StatusCode.ToString()))); failureCode = Telemetry.VcRemoteFailureCode.VcRemoteUnkown.ToString(); } } else { exceptionDispatchInfo = ExceptionDispatchInfo.Capture(new LauncherException(LauncherResources.Error_UnableToReachServer)); failureCode = Telemetry.VcRemoteFailureCode.VcRemoteNoConnection.ToString(); } } catch (TaskCanceledException) { //timeout exceptionDispatchInfo = ExceptionDispatchInfo.Capture(new LauncherException(LauncherResources.Error_UnableToReachServer)); failureCode = Telemetry.VcRemoteFailureCode.VcRemoteNoConnection.ToString(); } catch (Exception e) { exceptionDispatchInfo = ExceptionDispatchInfo.Capture(e); failureCode = e.GetType().FullName; } doneEvent.Set(); Telemetry.SendLaunchError(failureCode, _launchOptions.IOSDebugTarget); }); waitLoop.Wait(doneEvent, cancellationTokenSource); if (exceptionDispatchInfo != null) { exceptionDispatchInfo.Throw(); } if (response == null) { Debug.Fail("Null resposne? Should be impossible."); throw new InvalidOperationException(); } responseBody = content; return response; }