C# – Deserialize JSON as a stream

Here’s an example of deserializing a JSON file as a stream with System.Text.Json: Stream deserialization has three main benefits: It’s memory-efficient, which improves overall performance. Fail fast when there’s a problem in the JSON data. Deserialization process can be canceled (async version only). In this article, I’ll go into details about these benefits and show … Read more

C# – How to cancel an HttpClient request

It’s a good idea to provide users with a way to cancel a HttpClient request that’s taking too long. To be able to cancel an HttpClient request, you can pass in a CancellationToken: To get a CancellationToken, you have to create a CancellationTokenSource: To actually cancel the request, you have to call CancellationTokenSource.Cancel(): This means … Read more