private static async Task InvokeDemoService() { OperationResult response; using (var cancellationSource = new CancellationTokenSource()) using (var client = new DemoServiceClient()) { cancellationSource.CancelAfter(TimeSpan.FromSeconds(1)); response = await client.RunOperationAsync(TimeSpan.FromSeconds(5), cancellationSource.Token).ConfigureAwait(false); } Console.WriteLine("ExecutionTime: {0}", response.ExecutionTime); Console.WriteLine("IsCanceled: {0}", response.IsCanceled); }
private static async Task InvokeDemoService() { OperationResult response; using (var cancellationSource = new CancellationTokenSource()) using (var client = new DemoServiceClient()) { // !!! ServiceModel.Cancellation demo: set-up client to support cancellation client.UseCancellation(); ////// !!! ServiceModel.Cancellation demo: set-up client to support cancellation custom client factory ////client.UseCancellation(o => o.ContractFactory = CancellationContractClientFactory.CreateClient); cancellationSource.CancelAfter(TimeSpan.FromSeconds(1)); response = await client.RunOperationAsync(TimeSpan.FromSeconds(5), cancellationSource.Token).ConfigureAwait(false); } Console.WriteLine("ExecutionTime: {0}", response.ExecutionTime); Console.WriteLine("IsCanceled: {0}", response.IsCanceled); }