Introduction

The C# async/await feature is used extensively within the library. It provides a cooperative parallelism, where tasks can interleave only where an await statement separates two portions of code. This makes it possible not to worry about threading and locks (although they are still available, if you need to perform CPU-intensive computations).

Task safety

The Shaman library is task-safe, but not thread-safe. That is, all the code which interacts with Shaman should be come from a single thread. This happens by default if you use async/await on a desktop or Windows Store app, but not in a console application. In this case, you need to create a SingleThreadSynchronizationContext.

SingleThreadSynchronizationContext

This class makes it possible to run async code within a synchronous context. The Run method should be called once when you start your console application.
SingleThreadSynchronizationContext.Run(async () =>
{
    await YourCodeAsync();
});
The difference between using SingleThreadSynchronizationContext and task.Wait() is that in the latter case the continuation will NOT be guaranteeded to run in the original SynchronizationContext. This means that parts of the code could start running on different threads, invalidating your task-safety assumptions.