Hello Nick
Thank you for the sample. I spent the past four hours on this issue.
Although I have not figured out the cause of the symptom, I'd like to
update you about my current research results.
1. I debugged your sample in x64 and x86 machines and noticed that the
_OVERLAPPED struct's Internal and InternalHigh values were set differently:
x64:
KERNEL32!_OVERLAPPED
+0x000 Internal : 0x103
+0x008 InternalHigh : 0 ' always 0
+0x010 Offset : 0
+0x014 OffsetHigh : 0
+0x010 Pointer : (null)
+0x018 hEvent : 0x00000000`00000220
x86:
KERNEL32!_OVERLAPPED
+0x000 Internal : 0
+0x004 InternalHigh : 0x10 ' this is the right value.
+0x008 Offset : 0
+0x00c OffsetHigh : 0
+0x008 Pointer : (null)
+0x010 hEvent : 0x000001f8
"Internal" holds the processed I/O's error code. Both 0x103 and 0 mean that
the operation is successful (SUCCEEDED(Internal) == TRUE). However, I feel
that there must be some meaning behind 0x103. I am asking the OS team about
it and hope this can give some insights of the cause.
2. I also discussed the issue with the .NET team. They reminded me that we
added the built-in managed pipe APIs in .NET 3.5 (see System.IO.Pipes
http://msdn.microsoft.com/en-us/library/system.io.pipes.aspx), so we
recommend just using that instead of rolling our own support for pipes.
Doing low-level async I/O in managed code is very hard.
In addition, the .NET team tells me that NativeOverlapped should work just
fine on both architectures.
3. I suspected that the problem here is that we are not pinning the object
containing the NativeOverlapped. CAsyncHelper is not blittable
(
http://msdn.microsoft.com/en-us/library/75dwhxf7.aspx), and thus cannot be
pinned. I manually pinned the NativeOverlapped struct inside it and
allocate a GCHandle on the ManualResetEvent object, but it does not work
out the problem. I'm still researching in this aspect.
4. Another suggestion we'd give is to look at binding the pipe to the
ThreadPool (via ThreadPool.BindHandle) and using Overlapped instead of
using NativeOverlapped directly. This makes the pinning stuff somewhat
easier, and gives a much nicer completion model.
Best Regards,
Jialiang Ge
Microsoft Online Community Support
=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================