Skip to main content
Filter by
Sorted by
Tagged with
Best practices
0 votes
6 replies
130 views

I understand that ConfigureAwait(false) prevents capturing the current synchronization context, allowing the continuation to run on any available thread. However, I’m not clear about if there is any ...
Vasantha Kumar's user avatar
2 votes
0 answers
186 views

I have an ASP.NET app running on .NET 4.8. I am getting a StackOverflowException. I have an action method that calls another method CallBackMethod where using ConfigureAwait(false) in a statement that ...
RKS's user avatar
  • 140
1 vote
1 answer
257 views

Inside an async method in C#, I need to defer the execution (return the execution to the caller), and also to clear the synchronization context before proceeding with the execution. The statement ...
Ricardo Rocha's user avatar
4 votes
1 answer
886 views

I am trying to understand the impact of setting ConfigureAwait(false) in an async foreach loop? await foreach (var item in data.ConfigureAwait(false)) { //... } Exactly where do we lose the ...
Joe Markov's user avatar
1 vote
1 answer
268 views

I recently saw this in code: await QueryAsync.ConfigureAwait(SynchronizationContext.Current is not null || TaskScheduler.Current != TaskScheduler.Default) My first thought was, "that's not right&...
TadGhostal's user avatar
2 votes
1 answer
342 views

I May have a misconception about something. For me in an async method, having ConfigureAwait(false); will permit the task to continue being executed on the threadpool. So if I Declare a LongRunning ...
Duagt's user avatar
  • 51
0 votes
1 answer
150 views

Is the following C# code guaranteed to have always sent a message if it is recorded as having been sent in the database, or does the ConfigureAwait(false) mean it is possible to have recorded ...
andrew pate's user avatar
  • 4,377
0 votes
1 answer
361 views

Why does this test fail? [Test] public async Task Test_Keeps_SynchronizationContext() { SynchronizationContext.Current.Should().NotBeNull(); // OK await Task.Delay(1).ConfigureAwait(true); ...
Waescher's user avatar
  • 5,797
4 votes
1 answer
4k views

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 ...
Novox's user avatar
  • 804
3 votes
2 answers
436 views

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: ...
sjb-sjb's user avatar
  • 1,235
0 votes
1 answer
1k views

Client starts some action via button. In controller its async method: async public Task<JsonResult> CreatePresentation that contains a line of code using (var response = await client.SendAsync(...
usernumber124153's user avatar
3 votes
2 answers
3k views

I have this: Parallel.ForEach(numbers, (number) => { var value = Regex.Replace(number, @"\s+", "%20"); tasks.Add(client.GetAsync(url + value)); }); await Task.WhenAll(...
MarchalPT's user avatar
  • 1,606
0 votes
1 answer
2k views

Let's say I got an async method in C# .Net Core: public Task<ResultClass> Action() { ... } What is the difference between invoking: ResultClass res = await Action(); and invoking: ResultClass ...
CodeMonkey's user avatar
  • 12.6k
2 votes
1 answer
251 views

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 ...
avhhh's user avatar
  • 281
0 votes
1 answer
585 views

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; ...
Eynat Sagiv's user avatar
0 votes
0 answers
388 views

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<CreateAuthorCommand, Author>...
fingers10's user avatar
  • 8,449
2 votes
1 answer
852 views

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 ...
binginsin's user avatar
  • 124
0 votes
0 answers
152 views

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 ...
GH DevOps's user avatar
  • 512
1 vote
1 answer
219 views

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 ...
João Sequeira's user avatar
79 votes
3 answers
84k views

I've read about ConfigureAwait in various places (including SO questions), and here are my conclusions: ConfigureAwait(true): Runs the rest of the code on the same thread the code before the await ...
Youssef13's user avatar
  • 5,352
0 votes
1 answer
4k views

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 ...
Amit Agrawal's user avatar
9 votes
2 answers
2k views

DotNet Fiddle link https://dotnetfiddle.net/GqA32R I have the following sample code to demonstrate the async local functionality static AsyncLocal<string> _asyncLocalString = new AsyncLocal<...
user2133404's user avatar
  • 1,867
4 votes
1 answer
3k views

I am working on Dotnet Core Blazor and getting below error while using EventCallBack to bind the parent grid after delete events. Below the code for using Child component <tbody> @foreach ...
Arun Singh's user avatar
2 votes
0 answers
631 views

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(); ...
Ananya Agarwal's user avatar
4 votes
3 answers
1k views

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 ...
S Itzik's user avatar
  • 564
1 vote
0 answers
223 views

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 ...
Solid's user avatar
  • 45
0 votes
1 answer
260 views

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<ActionResult> MyAction() { await ...
jstuardo's user avatar
  • 4,497
1 vote
1 answer
106 views

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 ...
jstuardo's user avatar
  • 4,497
4 votes
1 answer
957 views

I've read here https://blog.stephencleary.com/2009/10/synchronizationcontext-properties.html that ASP.NET applications' execution context does not have specific associated thread. Does it mean code ...
Denys Alexieiev's user avatar
0 votes
1 answer
2k views

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(...
AlvinfromDiaspar's user avatar
-1 votes
1 answer
369 views

The latest version of the Quartz library switched everything to use async/await. The calling application has synchronous calls that are very embedded in the framework, so I am stuck calling ....
user756366's user avatar
0 votes
1 answer
256 views

I've got an ASP.NET WebForms application which has pages using Async=True and I'm using RegisterAsyncTask(new PageAsyncTask(InitialiseAsync)); in my OnLoad method to call business logic asynchronously....
Chris Walsh's user avatar
  • 3,523
1 vote
2 answers
150 views

I've got an issue calling a method that may return a Task<T> or null depending on the result of an initial synchronous lookup call (this itself might be an anti-pattern so please let me know). ...
Chris Walsh's user avatar
  • 3,523
2 votes
2 answers
4k views

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 ...
Michael's user avatar
  • 3,682
0 votes
0 answers
56 views

If I set ConfigureAwait (false) in the logic I also need to specify it in the WebApi? ASP.NET My Business Logic Using ConfigureAwait My WebApi Here you also have to set ConfigureAwait?
Long Stive Vega's user avatar
4 votes
1 answer
4k views

I am developing a server in ASP NET Core 3.1 preview edition and now i see that for all my async methods when calling await i get CA2007 warning (as it is when some task is running asynchronous). Is ...
Bercovici Adrian's user avatar
2 votes
0 answers
409 views

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 ...
Pablo Gonzalez's user avatar
4 votes
2 answers
2k views

Implementing a reusable adaptor type of library on top of Azure Document Db Client SDK. The library can run anywhere, not only in an ASP.NET Core web service, but in a command line app, ASP.NET Web ...
Dogu Arslan's user avatar
  • 3,403
4 votes
0 answers
150 views

I have a question about using ConfigureAwait in .NET Core apps. I know that ASP.NET Core has so SynchronizationContext (http://blog.stephencleary.com/2017/03/aspnetcore-synchronization-context.html) ...
dnf's user avatar
  • 1,819
0 votes
2 answers
2k views

I have a library with async methods and I have read that for libraries, it is recommended to use ConfigureAwait(false). For example, if I have something like: public async Task myMethod01() { ...
Álvaro García's user avatar
0 votes
1 answer
406 views

I'm working on trying to understand how Task.ContinueWith works. Consider the following code: private async void HandleButtonClick(object sender, EventArgs e) { Console.WriteLine($"...
rory.ap's user avatar
  • 35.7k
2 votes
1 answer
748 views

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 ...
Александр Сысоев's user avatar
6 votes
1 answer
17k views

I have read: http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html and the accepted answer at deadlock even after using ConfigureAwait(false) in Asp.Net flow but am just too dense to see ...
Dave's user avatar
  • 8,701
1 vote
0 answers
146 views

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. ...
TMan's user avatar
  • 4,110
3 votes
1 answer
1k views

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 ...
stev-e's user avatar
  • 456
0 votes
0 answers
279 views

We have the following ASP.NET code (I've cut it down for clarity): var httpContent = new StringContent(postData, Encoding.UTF8); using (var client = this.GetClient(url, contentType)) { using (var ...
DrGriff's user avatar
  • 4,934
5 votes
1 answer
5k views

What is the best practice when returning the following Task: public async Task<Command> BuildCommunicationCommand As an object: public Command BuildCommand I have the following: public ...
James Blackburn's user avatar
1 vote
0 answers
81 views

If I have the following function public async Task<bool> Foo() { // call many async functions await Bar1().ConfigureAwait(false); await Bar2().ConfigureAwait(false); return await Bar3()....
Simon Goodman's user avatar
0 votes
1 answer
1k views

I have some C# code that Im actually porting to VB.Net. Now I noticed ConfigureAwait(false) is used everywhere. A requirement is that the code be dependant on .Net 4.0 As you might know... ...
Eminem's user avatar
  • 7,516
5 votes
2 answers
5k views

I was expecting to get back to Thread#1 at location 1.2, but I did not. Is there a way to get back to UI thread after making the async call? Thanks Also I cannot make the top level method async. Not ...
Carol's user avatar
  • 403