static class Program { static void Main(string[] args) { var test1 = SkipLinesAsync1(null, 1); test1.GetAwaiter().GetResult(); // throws here - only when awaited var test2 = SkipLinesAsync2(null, 1); // throws here - this is what you would expect test2.GetAwaiter().GetResult(); Console.ReadKey(); } public static async Task SkipLinesAsync1(this TextReader reader, int linesToSkip)
{ if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (linesToSkip < 0) { throw new ArgumentOutOfRangeException(nameof(linesToSkip)); }
await reader.SkipLinesInternalAsync(linesToSkip); } public static Task SkipLinesAsync2(this TextReader reader, int linesToSkip)
{ if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (linesToSkip < 0) { throw new ArgumentOutOfRangeException(nameof(linesToSkip)); }
return reader.SkipLinesInternalAsync(linesToSkip); }
private static async Task SkipLinesInternalAsync(this TextReader reader, int linesToSkip) { for (var i = 0; i < linesToSkip; ++i) { var line = await reader.ReadLineAsync().ConfigureAwait(false); if (line == null) { break; } } } }
--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/c659eb9f-9408-42ef-875c-da374277dafd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yes. But it comes with some stack trace erasure.
--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/b2fbb921-0cec-46db-a01c-39eb4565d108%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.