Socket.DuplicateAndClose(Int32) Socket.DuplicateAndClose(Int32) Socket.DuplicateAndClose(Int32) Socket.DuplicateAndClose(Int32) Method


重复目标进程的套接字引用,并关闭此进程的套接字。Duplicates the socket reference for the target process, and closes the socket for this process.

 System::Net::Sockets::SocketInformation DuplicateAndClose(int targetProcessId);
[System.MonoLimitation("We do not support passing sockets across processes, we merely allow this API to pass the socket across AppDomains")]
public System.Net.Sockets.SocketInformation DuplicateAndClose (int targetProcessId);
member this.DuplicateAndClose : int -> System.Net.Sockets.SocketInformation
Public Function DuplicateAndClose (targetProcessId As Integer) As SocketInformation


Int32 Int32 Int32 Int32

从中创建重复套接字引用的目标进程的 ID。The ID of the target process where a duplicate of the socket reference is created.


要传递到目标进程的套接字引用。The socket reference to be passed to the target process.


targetProcessID 不是有效的进程 ID。targetProcessID is not a valid process id. - 或 --or- 套接字引用的复制失败。Duplication of the socket reference failed.


目标进程应使用Socket创建重复套接字实例。The target process should use Socket to create the duplicate socket instance.

如果您调用Socket多次使用相同的字节数组,作为每个调用的参数的构造函数,您将创建多个托管Socket具有相同的基础套接字的实例。If you call the Socket constructor multiple times with the same byte array as the argument for each call, you will create multiple managed Socket instances with the same underlying socket. 这种做法是强烈建议不要使用。This practice is strongly discouraged.

如果进程创建套接字使用的异步方法 (BeginReceiveBeginSend),该过程必须首先设置UseOnlyOverlappedIO属性设置为 true; 否则为套接字绑定到完成端口的创建过程中,这可能会导致ArgumentNullException目标进程中抛出。If the process creating the socket uses asynchronous methods (BeginReceive or BeginSend), the process must first set the UseOnlyOverlappedIO property to true; otherwise, the socket is bound to the completion port of the creating process, which may cause an ArgumentNullException to be thrown on the target process.