Questions tagged [configureawait]

The ConfigureAwait is a .NET method available for the Task/ValueTask types, that configures an awaiter used to await these awaitables. It has a boolean parameter continueOnCapturedContext that takes the value true to marshal the continuation back to the original context captured, or false to not capture the context.

Documentation:

Articles:

Videos:

52 questions
3
votes
2 answers

ConfigureAwait(false) and struct implementation of IAsyncDisposable

I have implemented IAsyncDisposable with an ActionOnAsyncDispose struct as shown below. My understanding is that the compiler will not box it when it is in an async using statement: ActionOnDisposeAsync x = ...; await using (x) { …
sjb-sjb
  • 1,112
  • 6
  • 14
3
votes
2 answers

C# Parallel.ForEach and Task.WhenAll sometimes returning less values then supposed

I have this: Parallel.ForEach(numbers, (number) => { var value = Regex.Replace(number, @"\s+", "%20"); tasks.Add(client.GetAsync(url + value)); }); await Task.WhenAll(tasks).ConfigureAwait(false); foreach (var task in tasks) { …
MarchalPT
  • 1,268
  • 9
  • 28
3
votes
3 answers

ConfigureAwait(false) doesn't make the continuation code run in another thread

I have a code which runs on thread1. I call a function in a synchronic way (using async method but it shouldn't disturb me - async method doesn't turn code to be asynchronic). I have an await with ConfigureAwait set to false, so I understood the…
S Itzik
  • 494
  • 3
  • 12
3
votes
2 answers

Web API - ConfigureAwait(true) not working as I thought

I'm having some trouble understanding the in's and out's of "continueOnCapturedContext" from a .NET v4.6 WebAPI 2 standpoint. The problem I'm having is there doesn't appear to be any difference between ConfigureAwait(true) and…
3
votes
1 answer

Task doesn't Go to Faulted State If ConfigurAwait set to False

So here is what I'm trying to achieve. I launch a task and don't do wait/result on it. To ensure that if launched task goes to faulted state (for e.g. say throw an exception) I crash the process by calling Environment FailFast in Continuation. How…
Duleb
  • 571
  • 1
  • 5
  • 12
2
votes
1 answer

Does .NET 6's PeriodicTimer capture the current SynchronizationContext by default?

For PeriodicTimer (AsyncTimer at the time), regarding WaitForNextTickAsync, David Fowler mentioned "The execution context isn't captured" (here) via (here). However, given that was not necessarily the final implementation, I reviewed the…
Novox
  • 774
  • 2
  • 7
  • 24
2
votes
1 answer

How can blocking async calls cause a deadlock if async calls aren't necessarily executed on a different thread?

I recently read Stephen Cleary's post regarding possible deadlocks that occur when we call async code in synchronous methods here: https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html Regarding a slightly modified example here (all I…
avhhh
  • 229
  • 1
  • 3
  • 11
2
votes
0 answers

ConfigureAwait(false) not giving response and app get stuck

I am using refit in my xamarin.forms project to connect to the server and download some data. The code below works properly if server is online but when server is offline, I got stuck and I am not getting response from the ConfigureAwait(false)…
Pablo Gonzalez
  • 673
  • 2
  • 10
  • 24
2
votes
1 answer

Why HttpContext.Current is not null in async/await with ConfigureAwait

I have a library async function called from controller. I expected HttpContext.Current to be null after await with ConfigureAwait(false) everywhere, but in controller it is not null. Can somebody explain why? //in libraby public class MyClass { …
2
votes
1 answer

When is the Usage of ConfigureAwait(false) in ViewModels problematic?

I wonder in which situations I will run into problems when using ConfigureAwait(false) in my (Xamarin) MVVM approach. This is mainly because I do not fully understand the synchronization context a view and a viewmodel and its properties and the…
stev-e
  • 436
  • 6
  • 15
2
votes
0 answers

Calling Async Method in Net3.5 Deadlock

I am using .net3.5 and i have the following installed This operation freezes. Can anyone tell me what i should be doing differently? HttpClient Client; response = await Client.SendAsync(request, cancellationToken).ConfigureAwait(false); I…
flexxxit
  • 2,440
  • 5
  • 42
  • 69
1
vote
0 answers

Does an exception propagate using ConfigureAwait(false) with async Task and await?

I was feeling like I had quite a good grip on async await programming, but what happened today made me perplexed. I have been searching for an answer to this for a little while now, but was not able to find it anywhere. I have read quite a bit about…
binginsin
  • 104
  • 6
1
vote
1 answer

Task-Like and ConfigureAwait(false), is it possible?

I've been reading about task-like and awaitable types. I think I've got a good grasp on the basic mechanics of it (awaiter, asyncmethodbuilder...) but there's something amiss when I try to understand the usage of ConfigureAwait(false) in such…
1
vote
0 answers

Can you use ConfigureAwait(false) with Task.WhenAny()?

I'm trying to implement a task based interleaving pattern similar to below. This logic is in a library and so I'm trying to make use of ConfigureAwait(false) as I don't see a reason that the task must resume in the same context. In the below example…
Solid
  • 45
  • 1
  • 6
1
vote
1 answer

Is it really necessary to add .ConfigureAwait call when calling an awaitable method?

I am developing an application using Visual Studio 2019 with code validation. Some code validation hints are important, however, I am getting a lot of hints in my awaitable method calls, such as var appUser = await…
jstuardo
  • 3,901
  • 14
  • 61
  • 136