Where is FIle.ReadAll *** Async / WriteAll *** Async / AppendAll *** Asynchronous Methods?

There are a bunch of fairly convenient methods in File , for example ReadAll*** / WriteAll*** / AppendAll*** .

I came across a number of cases when I need their asynchronous copies, but they simply do not exist.

Why? Are there any pitfalls?
I know that these methods can be easily implemented, but are there any reasons not to implement them in your pocket out of the box?

+6
source share
1 answer

"... I need their asynchronous copies, but they just don't exist. Why?"

All XXXAsync methods that have been added to the .Net infrastructure along with asynchronous waiting (not counting new libraries designed with asynchrony in mind) are just wrappers around BeginXXX / EndXXX .

They did not add any new asynchronous operations, but simply turned the old into new, task-based. 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 is no File.BeginReadAll and File.EndReadAll , it is clear that there is no File.ReadAllAsync .

Are there any pitfalls?

The only mistake in implementing these methods is to make it truly asynchronous, not fake async.

+4
source

All Articles