在C#里使用同步的管道服务,有一个问题很难处理,
就是当连接过来的管道没有关闭时,服务端也不能退出程序,它会一直等到客户端关闭为止。
也没有别的办法去停止这个等待的过程。
因此,使用异步的方法就可以避免这个问题。
下面是服务器的例子:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApp20_pipe
{public partial class Form1 : Form{AsyncNamedPipeServer _pipeSvr = new AsyncNamedPipeServer();bool _isRunning = false;public Form1(){InitializeComponent();}private void button1_Click(object s