gpt4 book ai didi

c# - 退出因等待传入管道流而阻塞的应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 16:27:28 24 4
gpt4 key购买 nike

我有一个应用程序在一个线程中运行 NamedPipeServerStream 并像这样等待连接:

NamedPipeServerStream pipeServerTemp = new NamedPipeServerStream(PIP_NAME, PipeDirection.InOut, 254);
pipeServerTemp.WaitForConnection();

应用程序一直在等待新的连接,但是当我尝试终止应用程序时,进程在调用 WaitForConnection 时挂起。

我已经尝试中止有问题的线程,但它不会终止应用程序。

如何告诉 NamedPipeServerStream 停止监听连接?

编辑:

我可以看到 NamedPipeServerStream 有一个名为 EndWaitForConnection 的方法,但它需要对 IAsynchResult 的引用,我从哪里获取该对象?

最佳答案

在答案to another question中找到了我要找的解决方案.

对于它的值(value),我选择了连接到 Stream 然后立即关闭连接而不是使其异步的简单解决方案。

关于c# - 退出因等待传入管道流而阻塞的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12092413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com