简体   繁体   English

退出被阻止的应用程序,等待传入的管道流

[英]Exiting an application that is blocked waiting for an incoming pipe stream

I have an application that runs a NamedPipeServerStream in a thread and waits for connections on it like so: 我有一个在线程中运行NamedPipeServerStream并等待其连接的应用程序,如下所示:

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

The application is always waiting for new connections, but when I try to kill the app the process hangs on the call to WaitForConnection. 该应用程序始终在等待新的连接,但是当我尝试终止该应用程序时,该过程将挂起对WaitForConnection的调用。

I've tried aborting the thread in question but it doesn't kill the application. 我尝试中止有问题的线程,但是它不会终止应用程序。

How can I tell the NamedPipeServerStream to stop listening for connections? 如何告诉NamedPipeServerStream停止监听连接?

EDIT: 编辑:

I can see that NamedPipeServerStream has a method called EndWaitForConnection but it needs a reference to an IAsynchResult , where would I get that object? 我可以看到NamedPipeServerStream有一个名为EndWaitForConnection的方法,但它需要对IAsynchResult的引用,在哪里可以获取该对象?

Found the solution I was looking for in the answer to another question . 另一个问题的答案中找到了我寻找的解决方案。

For what it's worth I went for the simple solution of connecting to the Stream and then immediately closing the connection rather than making it asynchronous. 为了值得,我去了一个简单的解决方案,即连接到Stream,然后立即关闭连接而不是使其异步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM