title: Can I cancel StreamReader.ReadLineAsync with a CancellationToken?
body: <p>When I cancel my async method with the following content by calling the <code>Cancel()</code> method of my <code>CancellationTokenSource</code>, it will stop eventually. However since the line <code>Console.WriteLine(await reader.ReadLineAsync());</code> takes quite a bit to complete, I tried to pass my <code>CancellationToken</code> to <code>ReadLineAsync()</code> as well (expecting it to return an empty string) in order to make the method more responsive to my <code>Cancel()</code> call. However I could not pass a <code>CancellationToken</code> to <code>ReadLineAsync()</code>.</p>
  <p>Can I cancel a call to <code>Console.WriteLine()</code> or <code>Streamreader.ReadLineAsync()</code> and if so, how do I do it?</p>
  <p>Why is <code>ReadLineAsync()</code> not accepting a <code>CancellationToken</code>? I thought it was good practice to give async methods an optional <code>CancellationToken</code> parameter even if the method still completes after being canceled.</p>
  <pre><code>StreamReader reader = new StreamReader(dataStream);
  while (!reader.EndOfStream)
  {
      if (ct.IsCancellationRequested){
          ct.ThrowIfCancellationRequested();
          break;
      }
      else
      {
          Console.WriteLine(await reader.ReadLineAsync());
      }
  }
  </code></pre>
  <p><strong>Update</strong>:
  Like stated in the comments below, the <code>Console.WriteLine()</code> call alone was already taking up several seconds due to a poorly formatted input string of 40.000 characters per line. Breaking this down solves my response-time issues, but I am still interested in any suggestions or workarounds on how to cancel this long-running statement if for some reason writing 40.000 characters into one line was intended (for example when dumping the whole string into a file).</p>