Fragrance
|
Couple of times I have encountered the interaction between Task and IDisposable and sometimes it has left me with some serious code bug.
Let’s come to sample code which will explain the crux of the issue. Suppose you have below line of code
Now HttpClient does provides the async version of "GetString" which is "GetStringAsync", so we can write the above line of code as shown below:
Now the above code might look perfect and it may work fine sometime. But it has a serious code bug. In the second version, here's what happens:
Now below is the revised version which will run effectively
Now, if you see we have included the "async" and also the corresponding "await" keyword. And it runs effectively like this:
Comments
|
Categories
All
Archives
May 2020
|