Skip to content

Instantly share code, notes, and snippets.

@M-Yankov
Created November 23, 2016 08:25
Show Gist options
  • Save M-Yankov/842959099318476781721aec5c4157fd to your computer and use it in GitHub Desktop.
Save M-Yankov/842959099318476781721aec5c4157fd to your computer and use it in GitHub Desktop.
Sample async example.
private async Task<string> Execute()
{
// Keep watching for out of memory exception when using new string
string text = "First Line" + Environment.NewLine + "Second" + Environment.NewLine + new string('-', int.MaxValue / 33);
text += text;
StringReader reader = new StringReader(text);
Console.WriteLine("=Before=");
string readText = await reader.ReadLineAsync();
Console.WriteLine("=After=");
Console.WriteLine(readText);
return readText;
/* Result
* =Before=
* =After=
* First Line
*/
}
@M-Yankov
Copy link
Author

using (var reader = new System.IO.StringReader("My AweSome Test" + new string('-', 200000) + System.Environment.NewLine + "Second Line"))
{
    reader.ReadLineAsync().ContinueWith(t =>
    {
        System.Console.WriteLine(t.Result);
    }); 

    System.Console.WriteLine("-----After-------------");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment