using System.Collections.Generic;
using System.Diagnostics;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
public static void Main(string[] args)
Console.WriteLine("Hello World test");
var xxx = DoSomethingAsync();
public static async Task DoSomethingAsync()
await Task.Delay(TimeSpan.FromSeconds(1));
Console.WriteLine(value);
await Task.Delay(TimeSpan.FromSeconds(1));
Console.WriteLine(value);
async Task DoSomethingAsync()
await Task.Delay(TimeSpan.FromSeconds(1));
await Task.Delay(TimeSpan.FromSeconds(1));
async Task DoSomethingAsync()
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
public abstract Task PossibleExceptionAsync();
public abstract void LogException(Exception ex);
async Task TrySomethingAsync()
await PossibleExceptionAsync();
catch (NotSupportedException ex)
public abstract Task PossibleExceptionAsync();
public abstract void LogException(Exception ex);
async Task TrySomethingAsync()
Task task = PossibleExceptionAsync();
catch (NotSupportedException ex)
await Task.Delay(TimeSpan.FromSeconds(1));
public abstract void Rotate(float degrees);
void RotateMatrices(IEnumerable<Matrix> matrices, float degrees)
Parallel.ForEach(matrices, matrix => matrix.Rotate(degrees));
public abstract bool IsPrime(int value);
IEnumerable<bool> PrimalityTest(IEnumerable<int> values)
return values.AsParallel().Select(value => IsPrime(value));
void ProcessArray(double[] array)
() => ProcessPartialArray(array, 0, array.Length / 2),
() => ProcessPartialArray(array, array.Length / 2, array.Length)
void ProcessPartialArray(double[] array, int begin, int end)
Parallel.Invoke(() => { throw new Exception(); },
() => { throw new Exception(); });
catch (AggregateException ex)
Trace.WriteLine(exception);
Observable.Interval(TimeSpan.FromSeconds(1))
.Where(x => x.Value % 2 == 0)
.Select(x => x.Timestamp)
.Subscribe(x => Trace.WriteLine(x));
IObservable<DateTimeOffset> timestamps =
Observable.Interval(TimeSpan.FromSeconds(1))
.Where(x => x.Value % 2 == 0)
.Select(x => x.Timestamp);
timestamps.Subscribe(x => Trace.WriteLine(x));
Observable.Interval(TimeSpan.FromSeconds(1))
.Where(x => x.Value % 2 == 0)
.Select(x => x.Timestamp)
.Subscribe(x => Trace.WriteLine(x),
ex => Trace.WriteLine(ex));
var multiplyBlock = new TransformBlock<int, int>(item =>
throw new InvalidOperationException("Blech.");
var subtractBlock = new TransformBlock<int, int>(item => item - 2);
multiplyBlock.LinkTo(subtractBlock,
new DataflowLinkOptions { PropagateCompletion = true });
subtractBlock.Completion.Wait();
catch (AggregateException exception)
AggregateException ex = exception.Flatten();
Trace.WriteLine(ex.InnerException);