Questions tagged [async]
163 questions
108
votes
5 answers
Aren't the guidelines of async/await usage in C# contradicting the concepts of good architecture and abstraction layering?
This question concerns the C# language, but I expect it to cover other languages such as Java or TypeScript.
Microsoft recommends best practices on using asynchronous calls in .NET. Among these recommendations, let's pick two:
change the signature…

corentinaltepe
- 971
- 2
- 6
- 6
45
votes
6 answers
In JavaScript, how is awaiting the result of an async different than sync calls?
I'm having a hard time wrapping my head around the use of async/await and regular sync function calls in JavaScript.
Let's say I have two functions:
Function 1:
async function doSomething() {
const result = await doExpensiveOperation()
const…

noblerare
- 1,301
- 2
- 10
- 12
39
votes
2 answers
Who did async/await first?
Python added the async/await constructs in 3.5 in 2015. The Javascript community made steps towards it for a bazzillion years and finally added a very similar implementation to the draft in ES8 released in 2017 (From my understanding). Typescript…

Ziv
- 2,946
- 5
- 23
- 26
33
votes
6 answers
Asynchronous Programming in Functional Languages
I'm mostly a C/C++ programmer, which means that the majority of my experience is with procedural and object-oriented paradigms. However, as many C++ programmers are aware, C++ has shifted in emphasis over the years to a functional-esque style,…

Charles Salvia
- 7,342
- 1
- 35
- 33
33
votes
6 answers
Why would you ever 'await' a method, and then immediately interrogate its return value?
In this MSDN article, the following example code is provided (slightly edited for brevity):
public async Task Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
…

Robert Harvey
- 198,589
- 55
- 464
- 673
29
votes
4 answers
What determines which Javascript functions are blocking vs non-blocking?
I have been doing web-based Javascript (vanilla JS, jQuery, Backbone, etc.) for a few years now, and recently I've been doing some work with Node.js. It took me a while to get the hang of "non-blocking" programming, but I've now gotten used to using…

Sean
- 393
- 1
- 3
- 4
29
votes
5 answers
At what point is asynchronous reading of disk I/O more efficient than synchronous?
Assuming there is some bit of code that reads files for multiple consumers, and the files are of any arbitrary size: At what size does it become more efficient to read the file asynchronously? Or to put it another way, how small must a file be for…

blesh
- 899
- 1
- 9
- 15
24
votes
3 answers
How can I diagnose async/await deadlocks?
I am working with a new codebase that makes heavy use of async/await. Most of the people on my team are also fairly new to async/await. We generally tend to hold to Best Practices as Specified by Microsoft, but generally need our context to flow…

Telastyn
- 108,850
- 29
- 239
- 365
21
votes
3 answers
Calling multiple async services in parallel
I have few async REST services which are not dependent on each other. That is while "awaiting" a response from Service1, I can call Service2, Service3 and so on.
For example, refer below code:
var service1Response = await HttpService1Async();
var…

Ankit Vijay
- 1,568
- 3
- 10
- 13
18
votes
2 answers
Why does C# allow you to make an override async?
In C#, when you override a method, it is permitted to make the override async when the original method was not. This seems like poor form.
The example that brought me to this was this — I was brought in to assist with a load test problem. At around…

Peter T. LaComb Jr.
- 291
- 1
- 2
- 5
18
votes
3 answers
BackgroundWorker vs. Async/Await
I am new to C# development and wish to create a more responsive UI. In my preliminary research, I have seen two methods for achieving this:
Multi-threading in conjunction with the BackgroundWorker class.
The newer Async/Await modifiers.
Does…

robert.ecot
- 357
- 1
- 2
- 9
17
votes
3 answers
How to justify using await instead of .Result() or .Wait() in .NET Core?
Since the inception of .NET Core, console apps, function apps, ASP.NET etc. are not using synchronization context in async methods (so they're synchronizing straight to Thread Pool).
This means that using .Result() or .Wait() after async method…

kor_
- 279
- 1
- 2
- 7
16
votes
3 answers
How will C# 5 async support help UI thread synchronization issues?
I heard somewhere that C# 5 async-await will be so awesome that you will not have to worry about doing this:
if (InvokeRequired)
{
BeginInvoke(...);
return;
}
// do your stuff here
It looks like the callback of a await operation will happen…

Alex
- 3,228
- 1
- 22
- 25
16
votes
6 answers
Solutions to C# 5 async re-entrancy
So, something's been bugging me about the new async support in C# 5:
The user presses a button which starts an async operation. The call returns immediately and the message pump starts running again - that's the whole point.
So the user can press…

Nick Butler
- 303
- 3
- 8
15
votes
2 answers
When should I use StringBuilder or StringBuffer?
In a production web application, my fellow programmers used StringBuffer everywhere. Now I am taking care of application development and corrections. After reading StringBuilder and StringBuffer I have decided to replace all the StringBuffer code…

Satish Pandey
- 1,340
- 3
- 10
- 20