There are a bunch of rather convenient methods in File class, like ReadAll***/WriteAll***/AppendAll***.
I'm faced with a number of cases, when I need their asynchronous counterparts, but they just don't exist.
Why? Are there any pitfalls?
I know, that these methods could be easily implemented, but is there any reason to not implement them in the framework out-of-the-box?
"... I need their asynchronous counterparts, but they just don't exist. Why?"
All of the XXXAsync methods that were added to the .Net framework together with async-await (not including new libraries developed with async in mind) are simply wrappers around BeginXXX/EndXXX.
They didn't add any new asynchronous operations, they just converted old ones into new task-based ones. For example this is UdpClient.SendAsync:
public Task<int> SendAsync(byte[] datagram, int bytes)
{
return Task<int>.Factory.FromAsync(BeginSend, EndSend, datagram, bytes, null);
}
Since there are no File.BeginReadAll and File.EndReadAll it's understandable that there's no File.ReadAllAsync.
Are there any pitfalls?
The only pitfall with implementing these methods is doing so in a truly asynchronous manner and not faking async.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With