52 votes

Async method with three internal tasks

Short and clean using null-coalescing operator: ...
user avatar
  • 545
30 votes
Accepted

Use of Async/Await for EventHandlers

The things to consider when it comes to async event handlers are: Exceptions thrown for the handler might be rethrown on the UI ...
user avatar
  • 24k
24 votes

AsyncDictionary - Can you break thread safety?

The reason why there is no async API for a dictionary is, that all operations on a dictionary are so fast, that there is no need for asynchronicity. For concurrent scenarios there is the thread safe ...
user avatar
  • 8,498
21 votes
Accepted

Starting a fire and forget async method

Just fire the task without async/await. ...
user avatar
  • 1,990
21 votes
Accepted

Async method with three internal tasks

Use the return pattern: ...
user avatar
18 votes
Accepted

Simon Says: "Make me a pretty game"

Well, first questions is: why don't you use MVVM? Contents of your App class look like something that should be implemented on model/view model level. This looks ...
user avatar
  • 13k
15 votes

Simon Says: "Make me a pretty game"

Magic numbers, you have at least one of them in class App: private async Task PlaySequence() you should extract this to either a ...
user avatar
  • 50k
15 votes
Accepted

Async/await in Parallel.ForEach

Is it ok to have an async void method? Referencing Async/Await - Best Practices in Asynchronous Programming As already stated in the OP async void should be ...
user avatar
  • 3,196
13 votes

AsyncDictionary - Can you break thread safety?

Threading Design Your implementation has a very intrusive lock for all read and write operations, using the SemaphoreSlim with max concurrency 1. ...
user avatar
  • 13.8k
12 votes
Accepted

Calling synchronous code in asynchronous method

If it's really just removing an item from a dictionary (and not e.g. doing synchronous file IO), then Alternative 1 is the best. When you're using async for scalability (e.g. in ASP.NET), using ...
user avatar
  • 24k
12 votes

AsyncDictionary - Can you break thread safety?

It's pretty hard to break something that uses a global lock around everything. So this seems pretty thread-safe. But that doesn't answer the question of why you'd want to use this. Asynchronous ...
user avatar
  • 525
12 votes
Accepted

Using async / await with dynamic import() for ES6 modules

Approach 2 does not work because accoring to MDN: import '/modules/my-module.js'; Is how you import a module for Import a ...
user avatar
  • 568
11 votes
Accepted

Task timer async

Initial observation is that you should avoid async void like private async void start() { //... } except for event ...
user avatar
  • 3,196
10 votes

Asynchronous Circular Buffer in C#

Quick Review An API like this, dealing with thread-sensitive operations, requires time and effort to test and review rigorously. When I will find this time, I will do a thorough review. But here are ...
user avatar
  • 13.8k
10 votes

Asynchronously scrape fabric information

While you can put request parameters in the URI directly, it's usually neater to pass those using the params argument of ...
user avatar
  • 2,583
9 votes

Download Images as fast as possible

Just a few quick remarks (for now): vbNullString is a remnant of VB6 (which I think would be under the ...
user avatar
9 votes
Accepted

AsyncDictionary - Can you break thread safety?

If you modify the AsyncDictionary while enumerating its keys/values it throws InvalidOperationException (if the backing ...
user avatar
  • 2,864
8 votes
Accepted

Async wrapper around public API

There's something odd about your constructors - normally chained constructors call the constructor with the most parameters, not the other way around: ...
user avatar
8 votes

Simple SqlHelper which wraps ADO.NET methods

Nesting. You can reduce nesting by stacking the using blocks, like this: ...
user avatar
8 votes

Async insecurities

The first thing that needs to be addressed is the indentation and the spacing, because that's the real issue here. You should line your braces with the start of the line above it, like so : ...
user avatar
  • 12.3k
8 votes
Accepted

Pass Async function to new Promise constructor

There's simply no reason to wrap your existing promise with another promise and no reason to use await or async here either: <...
user avatar
  • 3,918
8 votes

Network helper class with retry logic on failure

Just wanted to add that you may want to consider using Polly instead of rolling your own retry mechanism - this is a library built specifically for this kind of retry mechanism (as well as many more ...
user avatar
8 votes
Accepted

Operation logger

One drawback I can think of this way of logging is that (correct me if I'm wrong) it is lazy. That's to say, until the root Op object is ...
user avatar
  • 2,889
7 votes
Accepted

Quicksort async vs serial

Your first mistake is to do something with async that is CPU bound. That is not what you use async code for, async code is good for IO bound work, not CPU bound work. That you have to use ...
user avatar
  • 461
7 votes
Accepted

Getting messages asynchronously using MailKit

It's hard to say how to write the ideal method for your use-case because you don't specify some of the details that would be necessary to know, such as: How often will your code be making this query? ...
user avatar
  • 186
7 votes
Accepted

Concurrent/parallel ForEachAsync - proper handling of exceptions and cancellations

Test Case 2 Correct, but only if those exceptions are thrown asynchronously. See (3) below. Correct. When you do await task.ContinueWith(...), you are no longer ...
user avatar
7 votes
Accepted

Network helper class with retry logic on failure

After our initial comment-review-update sequence/loop there is not much left for a review but still, one more thing. You can get rid of the if entirely when you add ...
user avatar
  • 43.8k
7 votes
Accepted

Simple async task scheduler

No way to stop the cycle. The standard with TPL is to use the CancellationToken. Even if it is not need now, which I don't know why, it would be easier in the future if it supported it. For example ...
user avatar
  • 4,096
7 votes

Asynchronous and recursive word square generator in C#

Algorithm It is always better to start out with a good decent algorithm before we try to optimize by vectorizing etc. Let’s look at what we need to do. Iterate through all the words (List<string&...
user avatar
  • 2,262

Only top scored, non community-wiki answers of a minimum length are eligible