ConfigureAwaitChecker icon indicating copy to clipboard operation
ConfigureAwaitChecker copied to clipboard

Proper rewrite for await using with variable

Open cincuranet opened this issue 3 years ago • 3 comments

For example this

await using (var test = ...)
{
}

with ConfigureAwait(false) will result in test being ConfiguredAsyncDisposable type.

cincuranet avatar Mar 11 '21 20:03 cincuranet

I was just about to post this. Current version of 5.0.0 calls this example code of mine as a possibility of missing ConfigureAwait(false):

await using FileStream fileStream = File.Open(sentryFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

How am I expected to rewrite this bit to satisfy the warning? I've tried various ideas that came to my mind but they all resulted in error of converting System.Runtime.CompilerServices.ConfiguredAsyncDisposable to System.IO.FileStream (in my case).

JustArchi avatar Mar 11 '21 21:03 JustArchi

Yeah, v5.0 was pushed few moments ago. I'm preparing the blog post.

You need to do something like this https://www.tabsoverspaces.com/233779-using-await-using-iasyncdisposable-with-configureawait.

cincuranet avatar Mar 11 '21 21:03 cincuranet

Thanks a lot, that did the trick!

Leaving the answer for people that might stumble upon this as well:

FileStream fileStream = File.Open(sentryFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

await using (fileStream.ConfigureAwait(false)) {
	// ...
}

JustArchi avatar Mar 11 '21 21:03 JustArchi