private Task<LiveOperationResult> ExecuteApiOperation(ApiOperation op, CancellationToken ct) { if (this.Session == null) { throw new LiveConnectException(ApiOperation.ApiClientErrorCode, ResourceHelper.GetString("UserNotLoggedIn")); } var tcs = new TaskCompletionSource<LiveOperationResult>(); op.OperationCompletedCallback = (LiveOperationResult opResult) => { if (opResult.IsCancelled) { tcs.TrySetCanceled(); } else if (opResult.Error != null) { tcs.TrySetException(opResult.Error); } else { tcs.TrySetResult(opResult); } }; ct.Register(op.Cancel); op.Execute(); return tcs.Task; }
private Task<LiveOperationResult> ExecuteApiOperation(ApiOperation op, CancellationToken ct) { var tcs = new TaskCompletionSource<LiveOperationResult>(); op.OperationCompletedCallback = (LiveOperationResult opResult) => { if (opResult.IsCancelled) { tcs.TrySetCanceled(); } else if (opResult.Error != null) { tcs.TrySetException(opResult.Error); } else { tcs.TrySetResult(opResult); } }; ct.Register(op.Cancel); op.Execute(); return tcs.Task; }