代码之家  ›  专栏  ›  技术社区  ›  Yuri Astrakhan

在单个进程中使用匿名PipeStreams时拒绝访问

  •  1
  • Yuri Astrakhan  · 技术社区  · 14 年前

    我需要在同一进程中有一个匿名管道,以允许两个库之间基于流的异步通信。

    一切正常,直到我打电话给流。读取()-我收到UnauthorizedAccessException-拒绝访问路径。有什么想法吗?

    using (var pipeServer = new AnonymousPipeServerStream(PipeDirection.Out))
    using (var pipeClient = new AnonymousPipeClientStream(PipeDirection.In, pipeServer.SafePipeHandle))
    {
        // External lib should close server pipe when it's done
        archFile.ExtractionFinished += (sender, args) => pipeServer.Close();
        archFile.BeginExtractFile(archFileName, pipeServer);
    
        var buf = new byte[1000];
    
        int read;
        while ((read = pipeClient.Read(buf, 0, buf.Length)) > 0)
        { ... }
    }
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Nicole Calinoiu    14 年前

    您需要使用将管道句柄作为字符串而不是安全句柄的客户机构造函数。例如。:

    using (var pipeServer = new AnonymousPipeServerStream(PipeDirection.Out))
    using (var pipeClient = new AnonymousPipeClientStream(PipeDirection.In, pipeServer.GetClientHandleAsString()))
    {
        //...
    }
    

    这一点记录在 http://msdn.microsoft.com/en-us/library/system.io.pipes.anonymouspipeclientstream.aspx .

        2
  •  -1
  •   Srivathsan M    12 年前