Is it possible to await an event instead of another async method?

You can use an instance of the SemaphoreSlim Class as a signal: private SemaphoreSlim signal = new SemaphoreSlim(0, 1); // set signal in event signal.Release(); // wait for signal somewhere else await signal.WaitAsync(); Alternatively, you can use an instance of the TaskCompletionSource<T> Class to create a Task<T> that represents the result of the button click: … Read more

Do HttpClient and HttpClientHandler have to be disposed between requests?

The general consensus is that you do not (should not) need to dispose of HttpClient. Many people who are intimately involved in the way it works have stated this. See Darrel Miller’s blog post and a related SO post: HttpClient crawling results in memory leak for reference. I’d also strongly suggest that you read the … Read more

What is the purpose of “return await” in C#?

There is one sneaky case when return in normal method and return await in async method behave differently: when combined with using (or, more generally, any return await in a try block). Consider these two versions of a method: Task<SomeResult> DoSomethingAsync() { using (var foo = new Foo()) { return foo.DoAnotherThingAsync(); } } async Task<SomeResult> … Read more

tech