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
  • 180,369
  • 20
  • 160
  • 215
neelesh bodgal
  • 632
  • 5
  • 14

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
  • 7,232
  • 6
  • 54
  • 115