本文整理汇总了C#中System.IO.Pipes.NamedPipeClientStream.EndRead方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeClientStream.EndRead方法的具体用法?C# NamedPipeClientStream.EndRead怎么用?C# NamedPipeClientStream.EndRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Pipes.NamedPipeClientStream
的用法示例。
在下文中一共展示了NamedPipeClientStream.EndRead方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginReadCallback
private void BeginReadCallback(IAsyncResult iar)
{
pipeClient = (NamedPipeClientStream)iar.AsyncState;
int bytesRead = pipeClient.EndRead(iar);
if (bytesRead > 0) {
readStringBuffer += Encoding.UTF8.GetString(readBuffer);
// if (pipeClient.IsMessageComplete) {
textBox1.Text += readStringBuffer + Environment.NewLine;
// readStringBuffer = "";
// }
}
BeginRead();
}
示例2: QvxCommandWorker
private void QvxCommandWorker()
{
try
{
if (pipeName == null) return;
object state = new object();
object connection = null;
using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut))
{
var buf = new byte[4];
var buf2 = new byte[4];
Int32 count = 0;
Int32 datalength = 0;
pipeClient.Connect(1000);
while (pipeClient.IsConnected)
{
try
{
#region Get QvxRequest
var iar = pipeClient.BeginRead(buf, 0, 4, null, state);
while (!iar.IsCompleted) Thread.Sleep(1);
count = pipeClient.EndRead(iar);
if (count != 4) throw new Exception("Invalid Count Length");
buf2[0] = buf[3];
buf2[1] = buf[2];
buf2[2] = buf[1];
buf2[3] = buf[0];
datalength = BitConverter.ToInt32(buf2, 0);
var data = new byte[datalength];
count = pipeClient.Read(data, 0, datalength);
if (count != datalength) throw new Exception("Invalid Data Length");
var sdata = ASCIIEncoding.ASCII.GetString(data);
sdata = sdata.Replace("\0", "");
QvxRequest request;
try
{
request = QvxRequest.Deserialize(sdata);
}
catch (Exception ex)
{
logger.Error(ex);
throw ex;
}
request.QVWindow = QVWindow;
request.Connection = connection;
#endregion
#region Handle QvxRequets
QvxReply result = null;
if (HandleQvxRequest != null)
result = HandleQvxRequest(request);
if (result == null)
result = new QvxReply() { Result = QvxResult.QVX_UNKNOWN_ERROR };
#endregion
#region Send QvxReply
sdata = " " + result.Serialize() + "\0";
datalength = sdata.Length - 4;
buf2 = ASCIIEncoding.ASCII.GetBytes(sdata);
buf = BitConverter.GetBytes(datalength);
buf2[0] = buf[3];
buf2[1] = buf[2];
buf2[2] = buf[1];
buf2[3] = buf[0];
pipeClient.Write(buf2, 0, buf2.Length);
pipeClient.WaitForPipeDrain();
#endregion
#region Handle result States
if (result.Terminate)
close = true;
if (result.Connection != null)
connection = result.Connection;
if (result.SetConnectionNULL)
connection = null;
#endregion
}
catch (Exception ex)
{
logger.Error(ex);
Thread.Sleep(500);
close = true;
}
if (close)
{
close = false;
pipeClient.Close();
}
Thread.Sleep(5);
}
}
running = false;
}
//.........这里部分代码省略.........