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
1
vote
2 answers

Trivial exit from a method that may perform an asynchronous call

I've got an issue calling a method that may return a Task or null depending on the result of an initial synchronous lookup call (this itself might be an anti-pattern so please let me know). I kind of want to return null if a trivial exit…
Chris Walsh
  • 3,423
  • 2
  • 42
  • 62
1
vote
2 answers

Should I use ConfigureAwait(false) in places like Repository?

Just read this article about ConfigureAwait and it made me think on an issue I haven't been able to come to peace with for some time now. Consider the code below. Each dependency uses await to make the call asynchronous. My concern is that each time…
Michael
  • 3,350
  • 2
  • 21
  • 35
1
vote
0 answers

Custom Code Inspection for ConfigureAwait

I have created my own way to essentially set ConfigureAwait(false) just once at the top of each async method which allows me to not have to append ConfigureAwait(false) at the end of each await call. Now I can just do something like: public async…
TMan
  • 4,044
  • 18
  • 63
  • 117
1
vote
0 answers

async Task() not returning straight away when not using await

If I have the following function public async Task Foo() { // call many async functions await Bar1().ConfigureAwait(false); await Bar2().ConfigureAwait(false); return await Bar3().ConfigureAwait(false); } If I call the function…
Simon Goodman
  • 1,174
  • 1
  • 8
  • 35
1
vote
1 answer

Async methods with or without ConfigureAwait on NetStandard lib for Net Core

I have a library that is doing bulk insert. Library is EfCore extension made in .NetStandard(1.4) so it can be used in ASP.NET Core projects targeting both .NetCore(1.0+) or full NetFramework(4.6.1+) One of the functions is: public static…
borisdj
  • 2,201
  • 3
  • 24
  • 31
0
votes
1 answer

Why does NUnit lose its SynchronizationContext after await?

Why does this test fail? [Test] public async Task Test_Keeps_SynchronizationContext() { SynchronizationContext.Current.Should().NotBeNull(); // OK await Task.Delay(1).ConfigureAwait(true); …
Waescher
  • 5,361
  • 3
  • 34
  • 51
0
votes
1 answer

UI thread waits for "await client.SendAsync(request).ConfigureAwait(false)" to finish before moving to another url

Client starts some action via button. In controller its async method: async public Task CreatePresentation that contains line using (var response = await client.SendAsync(request).ConfigureAwait(false)). Lets say this line takes 10s to…
0
votes
1 answer

What is the difference between await and ConfigureAwait(false).GetAwaiter().GetResult();

Let's say I got an async method in C# .Net Core: public Task Action() { ... } What is the difference between invoking: ResultClass res = await Action(); and invoking: ResultClass res =…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
0
votes
1 answer

ConfigureAwait , UI, await async

I have a small project - WinForms On .net frameWork - just a small test : private void button9_Click(object sender, EventArgs e) { string text = GetTitleAsync().Result; button9.Text = text; } private async Task
0
votes
0 answers

Consider Calling ConfigureAwait on the awaited task

I'm developing an web API using CQRS pattern. I have a command to Create Author. Here is my Command Handler: internal sealed class AddCommandHandler : ICommandHandler { private readonly IUnitOfWork _unitOfWork; …
fingers10
  • 6,675
  • 10
  • 49
  • 87
0
votes
0 answers

Async ConfigureAwait(false) Exception Handling-Long Running Processes

I have two long processes that are inside a Task.Run block that I want to run concurrently and capture any exceptions that may occur. I don't want to wait for these tasks to complete and I want to avoid deadlocks so I added ConfigureAwait(false). My…
GH DevOps
  • 305
  • 1
  • 11
0
votes
1 answer

ConfigureAwait(false) in .Net Core application

I am creating a cron job using .Net Core which will fetch data from API and insert data into database. Should I use ConfigureAwait(false) while calling api in asynchronous mode? I am confused after reading article - ConfigureAwait(false) relevant in…
0
votes
0 answers

S4462 issue: Calls to "async" methods should not be blocking. How to call asynchronous method from synchronous method?

I am trying to call an asynchronous method from a synchronous method. For instance: Let methodAsync be an asynchronous method. static void methodSync() { object1.methodAsync().Wait(); object1.methodAsync().Result; …
0
votes
1 answer

Cascading ConfigureAwait(false), is it necessary?

I am developing an MVC5 ASP.NET Application where I have the following question. If I have an action in a controller defined this way: public async Task MyAction() { await MethodAsync().ConfigureAwait(false); } Then, if…
jstuardo
  • 3,901
  • 14
  • 61
  • 136
0
votes
1 answer

Using ConfigureAwait() without await

I have a method called Load which is being invoked from a synchronous method: private async Task LoadAsync() { await Task.Run(() => // stuff....).ConfigureAwait(false); } public void HelloWorld() { this.LoadAsync(); // this gives me a…
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140