Can I catch an error from async without using await?

Dealing with unhandled rejected native promises (and async/await uses native promises) is a feature supported now in V8. It’s used in the latest Chrome to output debugging information when a rejected promise is unhandled; try the following at the Babel REPL: async function executor() { console.log(“execute”); } async function doStuff() { console.log(“do stuff”); throw new … Read more

Would a Task.Convert extension method be useful or does it have hidden dangers?

Transforming the result of await ends up being annoying in terms of precedence I generally prefer to introduce a local var, but as you noted, that prevents expression-bodied methods. We occasionally forget ConfigureAwait(false) – this is solvable with tooling to some extent Since you’re working on a library and should use ConfigureAwait(false) everywhere, it may … Read more

Why is an “await Task.Yield()” required for Thread.CurrentPrincipal to flow correctly?

How interesting! It appears that Thread.CurrentPrincipal is based on the logical call context, not the per-thread call context. IMO this is quite unintuitive and I’d be curious to hear why it was implemented this way. In .NET 4.5., async methods interact with the logical call context so that it will more properly flow with async … Read more

The request message was already sent. Cannot send the same request message multiple times

You are calling the same func parameter twice: var response = await ProcessRequestAsync(func); //… response = await ProcessRequestAsync(func); In this case func returns the same request every single time. It doesn’t generate a new one every time you call it. If you truly need a different request each time then func needs to return a … Read more

PEP 0492 – Python 3.5 async keyword

No, co-routines do not involve any kind of threads. Co-routines allow for cooperative multi-tasking in that each co-routine yields control voluntarily. Threads on the other hand switch between units at arbitrary points. Up to Python 3.4, it was possible to write co-routines using generators; by using yield or yield from expressions in a function body … Read more

using ThreadStatic variables with async/await

You could use CallContext.LogicalSetData and CallContext.LogicalGetData, but I recommend you don’t because they don’t support any kind of “cloning” when you use simple parallelism (Task.WhenAny / Task.WhenAll). I opened a UserVoice request for a more complete async-compatible “context”, explained in more detail in an MSDN forum post. It does not seem possible to build one … Read more

OperationContext.Current is null after first await when using async/await in WCF service

It is unfortunate that this doesn’t work and we will see about getting a fix out in a future release. In the mean time, there is a way to reapply the context to the current thread so that you don’t have to pass the object around: public async Task<double> Add(double n1, double n2) { OperationContext … Read more

Run async method regularly with specified interval

The async equivalent is a while loop with Task.Delay (which internally uses a System.Threading.Timer): public async Task PeriodicFooAsync(TimeSpan interval, CancellationToken cancellationToken) { while (true) { await FooAsync(); await Task.Delay(interval, cancellationToken) } } It’s important to pass a CancellationToken so you can stop that operation when you want (e.g. when you shut down your application). Now, … Read more