2
public static async ???? ReadFileLineByLineAsync(string file)
{

    using(StreamReader s = new StreamReader(file))
    {
        while (!s.EndOfStream)
            yield return await s.ReadLineAsync();
    }
}

I want to write a async function for reading a file line by line. what should be the return type of this function. I would appreciate any suggestions on this.

Dmitry Bychenko
  • 165,109
  • 17
  • 150
  • 199
neelesh bodgal
  • 630
  • 5
  • 13

1 Answers1

0

You could try using Reactive Linq Observable instead:

public static IObservable<string> ReadFileLineByLineAsync(string file)
{
  return Observable.Create<string>(
    (obs, token) =>
      Task.Factory.StartNew(
        () =>
        {
          using (var s = new StreamReader(file))
          {
            while (!s.EndOfStream)
              obs.OnNext(s.ReadLine());
          }
          obs.OnCompleted();
        },
        token));
}
Andreas Zita
  • 6,714
  • 5
  • 44
  • 110