System.IO.File
in .NET and .NET Core has a family of Read...Async()
methods, all of which return either Task<byte[]>
or Task<string>
(Task<T>
is the .NET's equivalent of Java's Future<T>
).
This looks largely equivalent to AsynchronousFileChannel
APIs (which either consume a CompletionHandler
or return a Future
), with one major difference.
AsynchronousFileChannel
uses a managed background thread to perform asynchronous I/O (the thread may be provided either by the default thread pool (sun.nio.ch.ThreadPool
) or by the ExecutorService
explicitly specified during channel creation).FileStream
implementation in .NET, on the other hand, passes FileOptions.Asynchronous
flag to the underlying operating system (see also Synchronous and Asynchronous I/O), doesn't spawn any managed background threads and uses what is called an Overlapped I/O.sun.nio.ch.WindowsAsynchronousFileChannelImpl
which is exactly an abstraction layer on top of Overlapped I/O.java.nio.channels.SelectableChannel
implementations for File I/O? If no, what are the technical limitations?It is not really possible. The Whole IO API would have to be re-implemented. NIO means non blocking I/O it is not the same as Asynchronous I/O. Non blocking is implemented in JAVA and long story short that means the OS has no ability to notify runtime that operation is completed. Isned java uses select()
or poll()
system calls to check if data is available.
I could talk about it but stollen picture is worth 100 words:
That is why in JAVA the separate thread is required to constantly call check,check,check,check .....
I don't know .NET platform but if what you posted is correct it utilizing asynchronous I/O so the last column. But I don't trust anything that comes from Microsoft.
Hope it answers your question. Also here I a additional reading material: https://stackoverflow.com/a/2625565/8951886
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