本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.EndRead方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.EndRead方法的具体用法?C# NamedPipeServerStream.EndRead怎么用?C# NamedPipeServerStream.EndRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Pipes.NamedPipeServerStream
的用法示例。
在下文中一共展示了NamedPipeServerStream.EndRead方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PipeServerAsyncEnumerator
private static IEnumerator<Int32> PipeServerAsyncEnumerator(AsyncEnumerator ae) {
// Each server object performs asynchronous operation on this pipe
using (var pipe = new NamedPipeServerStream(
"Echo", PipeDirection.InOut, -1, PipeTransmissionMode.Message,
PipeOptions.Asynchronous | PipeOptions.WriteThrough)) {
// Asynchronously accept a client connection
pipe.BeginWaitForConnection(ae.End(), null);
yield return 1;
// A client connected, let's accept another client
var aeNewClient = new AsyncEnumerator();
aeNewClient.BeginExecute(PipeServerAsyncEnumerator(aeNewClient),
aeNewClient.EndExecute);
// Accept the client connection
pipe.EndWaitForConnection(ae.DequeueAsyncResult());
// Asynchronously read a request from the client
Byte[] data = new Byte[1000];
pipe.BeginRead(data, 0, data.Length, ae.End(), null);
yield return 1;
// The client sent us a request, process it
Int32 bytesRead = pipe.EndRead(ae.DequeueAsyncResult());
// Just change to upper case
data = Encoding.UTF8.GetBytes(
Encoding.UTF8.GetString(data, 0, bytesRead).ToUpper().ToCharArray());
// Asynchronously send the response back to the client
pipe.BeginWrite(data, 0, data.Length, ae.End(), null);
yield return 1;
// The response was sent to the client, close our side of the connection
pipe.EndWrite(ae.DequeueAsyncResult());
} // Close happens in a finally block now!
}
示例2: BeginReadCallback
private void BeginReadCallback(IAsyncResult iar)
{
pipeServer = (NamedPipeServerStream)iar.AsyncState;
int bytesRead = pipeServer.EndRead(iar);
if (bytesRead > 0) {
receiveMessage += System.Text.Encoding.UTF8.GetString(receiveBuffer, 0, receiveBuffer.Length);
if (pipeServer.IsMessageComplete) {
OnReceiveMessageComplete(receiveMessage);
receiveMessage = "";
}
}
pipeServer.BeginRead(receiveBuffer, 0, receiveBuffer.Length, BeginReadCallback, pipeServer);
}
示例3: bw_DoWork
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
int count = 0;
BackgroundWorker worker = sender as BackgroundWorker;
const int BufferSize = 256;
System.Diagnostics.Debug.WriteLine("Start Background Worker");
if (dataSource == SourceFrom.UART)
{
SkytraqGps gps = e.Argument as SkytraqGps;
byte[] buff = new byte[BufferSize];
try
{
while (!worker.CancellationPending)
{
int l = gps.ReadLineNoWait(buff, 256, 1000);
if (buff[0] != 0xa0 || buff[1] != 0xa1 || buff[4] != 0x64 || buff[5] != 0xfd)
{
continue;
}
++count;
worker.ReportProgress(count, new IQInfo(
buff[6],
(UInt32)buff[7] << 8 | (UInt32)buff[8],
buff[9],
buff[10],
buff[11],
buff[12],
buff[13],
(Int32)((UInt32)buff[14] << 24 | (UInt32)buff[15] << 16 | (UInt32)buff[16] << 8 | (UInt32)buff[17]),
(Int16)((UInt32)buff[18] << 8 | (UInt32)buff[19]),
(Int16)((UInt32)buff[20] << 8 | (UInt32)buff[21])));
//Console.WriteLine("{0},{1},{2},{3},{4},{5}",
// gpsType, nmeaSvid, integrateionTime, doppler, iValue, qValue);
}
}
catch (Exception ep)
{
Console.WriteLine(ep.ToString());
}
}
else
{
//Initial Namedpipe ===========================================
while (!worker.CancellationPending)
{
System.Diagnostics.Debug.WriteLine("Pipe name :" + Program.pipeName);
using (NamedPipeServerStream pipeStream = new NamedPipeServerStream(Program.pipeName,
PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
{
ReceiveStatus rs = ReceiveStatus.None;
int packageSize = 0;
int ptr = 0;
int sharpLen = 0;
byte[] buff = new byte[BufferSize];
System.Diagnostics.Debug.WriteLine("Create Named Pipe :" + Program.pipeName);
//Wait for connection
while (!worker.CancellationPending)
{
try
{
if (!pipeStream.IsConnected)
{
//pipeStream.WaitForConnection();
var asyncResult = pipeStream.BeginWaitForConnection(null, null);
while (!worker.CancellationPending)
{
if (asyncResult.AsyncWaitHandle.WaitOne(5))
{
pipeStream.EndWaitForConnection(asyncResult);
break;
}
}
}
}
catch (Exception ep)
{
Console.WriteLine(ep.ToString());
Thread.Sleep(10);
break;
}
if (worker.CancellationPending)
{
return;
}
var asyncResult2 = pipeStream.BeginRead(buff, ptr, 1, null, null);
//Wait for data in
while (!worker.CancellationPending)
{
if (asyncResult2.AsyncWaitHandle.WaitOne(5))
{
pipeStream.EndRead(asyncResult2);
++ptr;
break;
}
}
//.........这里部分代码省略.........
示例4: QvxDataServerWorker
private void QvxDataServerWorker()
{
using (NamedPipeServerStream pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1))
{
pipeServer.WaitForConnection();
var buf = new byte[65536*20];
object state = new object();
while (running && pipeServer.IsConnected)
{
var iar = pipeServer.BeginRead(buf, 0, buf.Length, null, state);
while (!iar.IsCompleted) Thread.Sleep(1); // TODO: add Timeout possibility
var count = pipeServer.EndRead(iar);
Console.WriteLine("Date Read: " + count.ToString());//+ ASCIIEncoding.ASCII.GetString(buf, 0, count));
if (count > 0)
{
var sendBuf = new byte[count];
Array.Copy(buf, sendBuf, count);
lock (locksendQueue)
{
sendQueue.Add(sendBuf);
}
}
}
if (pipeServer.IsConnected) pipeServer.Close();
}
Console.WriteLine("PIPE finished");
lock (locksendQueue)
{
sendQueue.Add(new byte[0]);
}
running = false;
Console.WriteLine("Close QvxDataServerWorker");
}