简体   繁体   中英

Is WriteFileGather supported in the .NET Class Library

I would like to use the Overlapped IO functions in a .Net app, specifically WriteFileGather. Is this supported through the standard class library?

Bonus points: does it work in Mono?

There is no direct function in .NET BCL, but there are some classes that can help you with Windows I/O. 1) Initialize an instance of Overlapped class.

2) Call Pack with the callback.

3) Pass the resulting NativeOverlapped (the return value of Pack) to the WriteFileGather .

4) As I understand, your callback should be called on a worker thread when the operation is complete.

Be sure to read MSDN docs on WriteFileGather as there are some requirements, eg the data must be aligned on the system's page boundary (I think 4K on x86-x64, 8K on Itanium) etc. etc.

FileStream Class exposes a stream around a file, supporting both synchronous and asynchronous read and write operations. The default implementation of BeginWrite on a stream calls the Write method synchronously, which means that Write might block on some streams. However, instances of classes such as FileStream and NetworkStream fully support asynchronous operations if the instances have been opened asynchronously. Therefore, calls to BeginWrite will not block on those streams. The FileStream Class should work exactly the same on mono.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM