I'd like to make use of native overlapped IO methods (via P/Invoke) in C# in an async/await friendly manner.
The following give good instructions on how to use overlapped IO in general:
Question: How can I make use of Overlapped IO using await to determine when the operation is complete?
For example, how can I call the method CfHydratePlaceholder utilizing overlapped IO and using async/await to determine when it is finished.
I used the information from the mentioned sites to create an async/await friendly class for doing Overlapped IO:
Sample usage:
Note: It is important the the file handle remains valid until the
OverlappedAsync.Taskhas completed.Using this approach is convenient when using native methods that do not have counterparts in .NET. Here are some examples from the Cloud Filter API that can use this approach: