.net form案例大全
WinForm 自动更新程序
自定义组件
跑马灯效果Label
TextBox横线样式及占位提示
监控变量值改变
Visual Studio 2022如何支持低版本.NET框架
Winform 支持高DPI的几种方式
C#实现程序在系统托盘显示图标及开机自启动
VS2022 工具箱中不显示 Devexpress控件的问题
进程间通信
两个exe程序之间通信
管道通信
日志写入到RichTextBox中展示
多线程访问WinForms控件的方法
多线程
线程锁与单多线程简单使用
本文档使用 MrDoc 发布
-
+
首页
管道通信
# 引用 ```java using System.IO; using System.IO.Pipes; ``` # 发送端 ```java private void btn_send_Click(object sender, EventArgs e) { try { using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "Pipeline", PipeDirection.Out)) { pipeClient.Connect(3000); using (StreamWriter sw = new StreamWriter(pipeClient)) { sw.WriteLine(textBox1.Text); sw.Flush(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } ``` # 接收端 ```java private void Form1_Load(object sender, EventArgs e) { Task.Run(() => { while (true) { using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("Pipeline", PipeDirection.In, 1)) { pipeServer.WaitForConnection(); using (StreamReader sr = new StreamReader(pipeServer)) { this.Invoke(new Action(() => { label1.Text = sr.ReadToEnd(); })); } } } }); } ```
孙端己
2024年9月30日 11:30
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码