В попытке использовать динамические виртуальные каналы RDP. Я передаю результат WTSVirtualChannelQuery
с WTSVirtualFileHandle
в FileStream
, но он вызывает различные исключения. Почему?
Звоните:
public static FileStream Open(string channelName, WTS_CHANNEL_OPTION option = WTS_CHANNEL_OPTION.DYNAMIC)
{
// Open
SafeFileHandle pFile = null;
using (var sfh = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, channelName, option))
{
WtsAllocSafeHandle pBuffer = null;
try
{
int cbReturned;
if (!WTSVirtualChannelQuery(sfh, WTS_VIRTUAL_CLASS.FileHandle, out pBuffer, out cbReturned)
|| cbReturned < IntPtr.Size)
{
throw new Win32Exception();
}
pFile = new SafeFileHandle(Marshal.ReadIntPtr(pBuffer.DangerousGetHandle()), false);
}
finally
{
pBuffer?.Dispose();
}
}
// create
return new FileStream(pFile, FileAccess.ReadWrite, bufferSize: 32 * 1024 * 1024, isAsync: true);
}
Исключения:
System.ArgumentException: Handle does not support asynchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened synchronously (that is, it was not opened for overlapped I/O).
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access, Int32 bufferSize, Boolean isAsync)
и
System.IO.IOException: The handle is invalid.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.VerifyHandleIsSync()
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access, Int32 bufferSize, Boolean isAsync)