与 StreamWriter 异步使用命名管道

发布于 2024-09-11 01:19:23 字数 144 浏览 4 评论 0原文

我正在尝试使用 StreamWriter 通过命名管道发送字符串,但 StreamWriter 类仅提供同步操作。我可以使用 NamedPipeServerStream 类的 BeginWrite 方法,但我想知道为什么没有允许异步操作的编写器类。我错过了一些明显的东西吗?

I am trying to send a string over a named pipe using StreamWriter, but StreamWriter class only offers synchronous operations. I can use BeginWrite method of the NamedPipeServerStream class, but I wonder why there are no writer classes that would allow asynchronous operations. Am I missing something obvious?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-09-18 01:19:23

它会比原始流复杂得多。对于原始流,任何数量的数据都可能异步传入,系统只是将缓冲区传递给您。阅读器需要字符编码,可以将几个字节的原始数据转换为单个 Unicode 字符。这并不是不可能的,框架库只是没有做到这一点,所以您需要自己完成这项工作。

(根据您的需要,创建另一个线程并在其上同步执行操作可能会使编写程序变得更容易。请注意,当您使用 Begin/End 异步时,可伸缩性通常会更高。)

It would be significantly more complicated than for the raw streams. For the raw streams, any amount of data might come in asynchronously and the system just passes the buffer to you. The reader requires character encoding which may turn several bytes of raw data into a single Unicode character. Not that this would be impossible, the framework libraries just don't take it that far so you'll need to do this work yourself.

(Depending on your needs, creating another thread and performing the operations synchronously on it might make it easier to write your program. Note that scalability would be generally be higher when you use Begin/End async.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文