Skip to content

Instantly share code, notes, and snippets.

@damirarh
Created July 20, 2013 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damirarh/6046195 to your computer and use it in GitHub Desktop.
Save damirarh/6046195 to your computer and use it in GitHub Desktop.
private async Task<byte[]> ReadAsync(string filename)
{
var fileInfo = new FileInfo(filename);
using (var stream = new FileStream(filename, FileMode.Open))
{
var buffer = new byte[fileInfo.Length];
await Task<int>.Factory.FromAsync(stream.BeginRead, stream.EndRead, buffer, 0, buffer.Length, null);
return buffer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment