问题描述
我有一个 namedpipeServerStream,我想在遇到超时时停止读取它的管道。
这些是我的 Read 和 Read 回调函数,我在主程序循环中反复调用 Read, 实际上,我的问题是当 endread 发生超时时,如何手动(或以任何其他方式)调用我的回调函数。
private void Read()
{
tmpBuff = new byte[600];
inRead = true;
ReadTimer.Enabled = true;
len = 0;
try
{
_namedpipeserver.BeginRead(tmpBuff,600,ReadCallback,null);
}
catch (Exception ex) //disconnected/disposed
{
return;
}
}
static void ReadCallback(IAsyncResult ar)
{
int readbyte;
try
{
readbyte = _namedpipeserver.EndRead(ar);
if (readbyte > 0)
{
len = readbyte;
int packetLen = tmpBuff[0] + (tmpBuff[1] * 256);
Console.WriteLine(" packet len: " + packetLen + " bytes ");
readbyte = 0;
array = null;
array = new byte[packetLen];
Array.copy(tmpBuff,2,array,packetLen);
}
}
catch (IOException) //closed
{
return;
}
inRead = false;
}
感谢任何帮助。谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)