本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.CopyTo方法的具体用法?C# NamedPipeServerStream.CopyTo怎么用?C# NamedPipeServerStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Pipes.NamedPipeServerStream
的用法示例。
在下文中一共展示了NamedPipeServerStream.CopyTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public void Get(Stream s)
{
if (thr != null)
throw new InvalidOperationException("Can only serve one thing at a time!");
if (e != null)
throw new InvalidOperationException("Previous attempt failed!", e);
if (!s.CanWrite)
throw new ArgumentException("Stream must be readable!");
using (var evt = new ManualResetEventSlim())
{
thr = new Thread(delegate()
{
try
{
using (var srv = new NamedPipeServerStream(PipeName, PipeDirection.In))
{
evt.Set();
srv.WaitForConnection();
srv.CopyTo(s);
//srv.Flush();
}
}
catch (Exception ee)
{
e = ee;
}
});
thr.Start();
evt.Wait();
}
}
示例2: ProcessMessages
public bool ProcessMessages(NamedPipeServerStream server)
{
try
{
BinaryFormatter binForm = new BinaryFormatter();
using (MemoryStream memoryStream = new MemoryStream())
{
server.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
object data = binForm.Deserialize(memoryStream);
Application.Current.Dispatcher.InvokeAsync(() =>
{
string message = data as string;
if (message != null)
{
switch (message)
{
case "MainWindow":
{
foreach (Window win in Application.Current.Windows)
{
if (win.GetType() == typeof(MainWindow))
{
win.Activate();
return;
}
}
MainWindow mw = new MainWindow();
mw.Show();
mw.Activate();
break;
}
case "Exit":
{
Application.Current.Shutdown();
break;
}
}
}
else
{
var newGesture = data as Tuple<string, List<List<List<Point>>>>;
if (newGesture == null) return;
GestureDefinition gu = new GestureDefinition(new Gesture(newGesture.Item1, newGesture.Item2.Select(list => new PointPattern(list)).ToArray()), false);
gu.Show();
gu.Activate();
}
}, DispatcherPriority.Input);
}
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
}
示例3: ReadThreadStart
private void ReadThreadStart(NamedPipeServerStream decodePipe, Process encoder)
{
const int bufSize = 5 * 1024 * 1024;
byte[] buffer = new byte[bufSize];
if (!decodePipe.IsConnected)
decodePipe.WaitForConnection();
try
{
decodePipe.CopyTo(encoder.StandardInput.BaseStream);
}
catch (Exception ex)
{
Log.Error(ex);
}
encoder.StandardInput.BaseStream.Close();
}
示例4: RunAsync
public async Task<Stream> RunAsync(Stream output, string query, params string[] sqlArguments)
{
NamedPipeServerStream pipeServerStream = new NamedPipeServerStream("SqlBcpWrapper" + GetHashCode(), PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
pipeServerStream.BeginWaitForConnection(e =>
{
pipeServerStream.EndWaitForConnection(e);
while (pipeServerStream.IsConnected && !pipeServerStream.IsMessageComplete)
{
}
pipeServerStream.CopyTo(output);
output.Seek(0, SeekOrigin.Begin);
pipeServerStream.Disconnect();
pipeServerStream.Close();
}, this);
RunInternal("\\\\.\\pipe\\SqlBcpWrapper" + GetHashCode(), query, sqlArguments, null, null);
await Task.Run(() =>
{
while (pipeServerStream.IsConnected && !pipeServerStream.IsMessageComplete)
{
}
});
return output;
}