I've noticed that in some case, Visual Studio recommends to do this
await using var disposable = new Disposable();
// Do something
instead of this
using var disposable = new Disposable();
// Do something
What is the difference between using
and await using
?
How should I decide which one to use?
Classic sync using
Classic using calls the
Dispose()
method of an object implementing theIDisposable
interface.Is equivalent to
New async await using
The new await using calls and await the
DisposeAsync()
method of an object implementing theIAsyncDisposable
interface.Is equivalent to
The IAsyncDisposable Interface was added in
.NET Core 3.0
and.NET Standard 2.1
.