本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream类的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream类的具体用法?C# NamedPipeServerStream怎么用?C# NamedPipeServerStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamedPipeServerStream类属于System.IO.Pipes命名空间,在下文中一共展示了NamedPipeServerStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: startServer
private void startServer(object state)
{
try
{
var pipe = state.ToString();
using (var server = new NamedPipeServerStream(pipe, PipeDirection.Out))
{
server.WaitForConnection();
while (server.IsConnected)
{
if (_messages.Count == 0)
{
Thread.Sleep(100);
continue;
}
var bytes = _messages.Pop();
var buffer = new byte[bytes.Length + 1];
Array.Copy(bytes, buffer, bytes.Length);
buffer[buffer.Length - 1] = 0;
server.Write(buffer, 0, buffer.Length);
}
}
}
catch
{
}
}
开发者ID:jonwingfield,项目名称:AutoTest.Net,代码行数:27,代码来源:PipeJunction.cs
示例2: NamedPipeWriteViaAsyncFileStream
public async Task NamedPipeWriteViaAsyncFileStream(bool asyncWrites)
{
string name = Guid.NewGuid().ToString("N");
using (var server = new NamedPipeServerStream(name, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
{
Task serverTask = Task.Run(async () =>
{
await server.WaitForConnectionAsync();
for (int i = 0; i < 6; i++)
Assert.Equal(i, server.ReadByte());
});
WaitNamedPipeW(@"\\.\pipe\" + name, -1);
using (SafeFileHandle clientHandle = CreateFileW(@"\\.\pipe\" + name, GENERIC_WRITE, FileShare.None, IntPtr.Zero, FileMode.Open, (int)PipeOptions.Asynchronous, IntPtr.Zero))
using (var client = new FileStream(clientHandle, FileAccess.Write, bufferSize: 3, isAsync: true))
{
var data = new[] { new byte[] { 0, 1 }, new byte[] { 2, 3 }, new byte[] { 4, 5 } };
foreach (byte[] arr in data)
{
if (asyncWrites)
await client.WriteAsync(arr, 0, arr.Length);
else
client.Write(arr, 0, arr.Length);
}
}
await serverTask;
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:29,代码来源:Pipes.cs
示例3: MultiplexedPipeConnection
public MultiplexedPipeConnection(NamedPipeServerStream pipeServer, Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream multiplexedOutputStream)
: base(pipeServer.Write)
{
this.pipeServer = pipeServer;
this.outputPump = new MultiplexConnectionOutputPump(pipeServer.Read, multiplexedOutputStream.Write, Id);
this.outputPump.BeginRunPump(PumpComplete, null);
}
开发者ID:RobBlackwell,项目名称:PortBridge,代码行数:7,代码来源:MultiplexedPipeConnection.cs
示例4: PipesReader2
private static void PipesReader2(string pipeName)
{
try
{
var pipeReader = new NamedPipeServerStream(pipeName, PipeDirection.In);
using (var reader = new StreamReader(pipeReader))
{
pipeReader.WaitForConnection();
WriteLine("reader connected");
bool completed = false;
while (!completed)
{
string line = reader.ReadLine();
WriteLine(line);
if (line == "bye") completed = true;
}
}
WriteLine("completed reading");
ReadLine();
}
catch (Exception ex)
{
WriteLine(ex.Message);
}
}
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:27,代码来源:Program.cs
示例5: EnsurePipeInstance
private void EnsurePipeInstance()
{
if (_stream == null)
{
var direction = PipeDirection.InOut;
var maxconn = 254;
var mode = PipeTransmissionMode.Byte;
var options = _asyncMode ? PipeOptions.Asynchronous : PipeOptions.None;
var inbuf = 4096;
var outbuf = 4096;
// TODO: security
try
{
_stream = new NamedPipeServerStream(_pipeAddress, direction, maxconn, mode, options, inbuf, outbuf);
}
catch (NotImplementedException) // Mono still does not support async, fallback to sync
{
if (_asyncMode)
{
options &= (~PipeOptions.Asynchronous);
_stream = new NamedPipeServerStream(_pipeAddress, direction, maxconn, mode, options, inbuf,
outbuf);
_asyncMode = false;
}
else
{
throw;
}
}
}
}
开发者ID:nsuke,项目名称:thrift,代码行数:32,代码来源:TNamedPipeServerTransport.cs
示例6: ListenForArguments
/// <summary>
/// Listens for arguments on a named pipe.
/// </summary>
/// <param name="state">State object required by WaitCallback delegate.</param>
private void ListenForArguments(Object state)
{
try
{
using (NamedPipeServerStream server = new NamedPipeServerStream(identifier.ToString()))
using (StreamReader reader = new StreamReader(server))
{
server.WaitForConnection();
List<String> arguments = new List<String>();
while (server.IsConnected)
{
string line = reader.ReadLine();
if (line != null && line.Length > 0)
{
arguments.Add(line);
}
}
ThreadPool.QueueUserWorkItem(new WaitCallback(CallOnArgumentsReceived), arguments.ToArray());
}
}
catch (IOException)
{ } //Pipe was broken
finally
{
ListenForArguments(null);
}
}
开发者ID:miracle091,项目名称:transmission-remote-dotnet,代码行数:32,代码来源:NamedPipeSingleInstance.cs
示例7: LaunchServer
private void LaunchServer(string pipeName)
{
try
{
Console.WriteLine("Creating server: " + pipeName);
server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 4);
Console.WriteLine("Waiting for connection");
server.WaitForConnection();
reader = new StreamReader(server);
Task.Factory.StartNew(() =>
{
Console.WriteLine("Begin server read loop");
while (true)
{
try
{
var line = reader.ReadLine();
messages.Enqueue(line);
}
catch (Exception ex)
{
Console.WriteLine("ServerLoop exception: {0}", ex.Message);
}
}
});
}
catch (Exception ex)
{
Console.WriteLine("LaunchServer exception: {0}", ex.Message);
}
}
开发者ID:zhsuiy,项目名称:actsynth,代码行数:32,代码来源:UIWindow.cs
示例8: StartImportServer
private static async void StartImportServer()
{
Log.Info("Started server");
var exceptionCount = 0;
while(exceptionCount < 10)
{
try
{
using(var pipe = new NamedPipeServerStream("hdtimport", PipeDirection.In, 1, PipeTransmissionMode.Message))
{
Log.Info("Waiting for connecetion...");
await Task.Run(() => pipe.WaitForConnection());
using(var sr = new StreamReader(pipe))
{
var line = sr.ReadLine();
var decks = JsonConvert.DeserializeObject<JsonDecksWrapper>(line);
decks.SaveDecks();
Log.Info(line);
}
}
}
catch(Exception ex)
{
Log.Error(ex);
exceptionCount++;
}
}
Log.Info("Closed server. ExceptionCount=" + exceptionCount);
}
开发者ID:JDurman,项目名称:Hearthstone-Deck-Tracker,代码行数:29,代码来源:PipeServer.cs
示例9: StartGeneralServer
private static async void StartGeneralServer()
{
Log.Info("Started server");
var exceptionCount = 0;
while(exceptionCount < 10)
{
try
{
using(var pipe = new NamedPipeServerStream("hdtgeneral", PipeDirection.In, 1, PipeTransmissionMode.Message))
{
Log.Info("Waiting for connecetion...");
await Task.Run(() => pipe.WaitForConnection());
using(var sr = new StreamReader(pipe))
{
var line = sr.ReadLine();
switch(line)
{
case "sync":
HearthStatsManager.SyncAsync(false, true);
break;
}
Log.Info(line);
}
}
}
catch(Exception ex)
{
Log.Error(ex);
exceptionCount++;
}
}
Log.Info("Closed server. ExceptionCount=" + exceptionCount);
}
开发者ID:JDurman,项目名称:Hearthstone-Deck-Tracker,代码行数:33,代码来源:PipeServer.cs
示例10: Listener
public Listener(StreamReader reader, NamedPipeServerStream server)
{
serverStream = server;
SR = reader;
thread = new Thread(new ThreadStart(Run));
thread.Start();
}
开发者ID:Microsoft,项目名称:WindowsProtocolTestSuites,代码行数:7,代码来源:PipeSinkServer.cs
示例11: CreatePipeServer
private void CreatePipeServer()
{
pipeServer = new NamedPipeServerStream("www.pmuniverse.net-installer", PipeDirection.InOut, 1, (PipeTransmissionMode)0, PipeOptions.Asynchronous);
pipeServer.WaitForConnection();
//pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnected), pipeServer);
Pipes.StreamString streamString = new Pipes.StreamString(pipeServer);
while (pipeServer.IsConnected) {
string line = streamString.ReadString();
if (!string.IsNullOrEmpty(line)) {
if (line.StartsWith("[Status]")) {
installPage.UpdateStatus(line.Substring("[Status]".Length));
} else if (line.StartsWith("[Progress]")) {
installPage.UpdateProgress(line.Substring("[Progress]".Length).ToInt());
} else if (line.StartsWith("[Component]")) {
installPage.UpdateCurrentComponent(line.Substring("[Component]".Length));
} else if (line == "[Error]") {
throw new Exception(line.Substring("[Error]".Length));
} else if (line == "[InstallComplete]") {
installPage.InstallComplete();
break;
}
}
}
pipeServer.Close();
}
开发者ID:ChaotixBluix,项目名称:Installer,代码行数:32,代码来源:InstallerProcessHelper.cs
示例12: Main
static void Main()
{
using (var pipeServer =
new NamedPipeServerStream("testpipe", PipeDirection.Out))
{
try
{
Console.WriteLine("NamedPipeServerStream object created.");
// Wait for a client to connect
Console.Write("Waiting for client connection...");
pipeServer.WaitForConnection();
Console.WriteLine("Client connected.");
// Read user input and send that to the client process.
using (StreamWriter sw = new StreamWriter(pipeServer))
{
sw.AutoFlush = true;
while (true)
{
Console.Write("Enter text: ");
sw.WriteLine(Console.ReadLine());
}
}
}
catch (IOException e)
{
Console.WriteLine("ERROR: {0}", e.Message);
}
}
}
开发者ID:hanei0415,项目名称:ManageMultiProcess,代码行数:35,代码来源:Program.cs
示例13: Run
public void Run()
{
while (true)
{
NamedPipeServerStream pipeStream = null;
try
{
pipeStream = new NamedPipeServerStream(ConnectionName, PipeDirection.InOut, -1, PipeTransmissionMode.Message);
pipeStream.WaitForConnection();
if (_stop)
return;
// Spawn a new thread for each request and continue waiting
var t = new Thread(ProcessClientThread);
t.Start(pipeStream);
}
catch (Exception)
{
if (pipeStream != null)
pipeStream.Dispose();
throw;
}
}
// ReSharper disable once FunctionNeverReturns
}
开发者ID:lgatto,项目名称:proteowizard,代码行数:25,代码来源:RemoteService.cs
示例14: PipeLink
public PipeLink(string spec)
{
this.pipe = new NamedPipeServerStream(spec, PipeDirection.InOut, 1, PipeTransmissionMode.Byte);
Thread t = new Thread(this.Connect);
t.Name = "Pipe Connector";
t.Start();
}
开发者ID:coderforlife,项目名称:lcd-emu,代码行数:7,代码来源:PipeLink.cs
示例15: Run
/// <summary>
/// Runs the bundle with the provided command-line.
/// </summary>
/// <param name="commandLine">Optional command-line to pass to the bundle.</param>
/// <returns>Exit code from the bundle.</returns>
public int Run(string commandLine = null)
{
WaitHandle[] waits = new WaitHandle[] { new ManualResetEvent(false), new ManualResetEvent(false) };
int returnCode = 0;
int pid = Process.GetCurrentProcess().Id;
string pipeName = String.Concat("bpe_", pid);
string pipeSecret = Guid.NewGuid().ToString("N");
using (NamedPipeServerStream pipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1))
{
using (Process bundleProcess = new Process())
{
bundleProcess.StartInfo.FileName = this.Path;
bundleProcess.StartInfo.Arguments = String.Format("{0} -burn.embedded {1} {2} {3}", commandLine ?? String.Empty, pipeName, pipeSecret, pid);
bundleProcess.StartInfo.UseShellExecute = false;
bundleProcess.StartInfo.CreateNoWindow = true;
bundleProcess.Start();
Connect(pipe, pipeSecret, pid, bundleProcess.Id);
PumpMessages(pipe);
bundleProcess.WaitForExit();
returnCode = bundleProcess.ExitCode;
}
}
return returnCode;
}
开发者ID:Jeremiahf,项目名称:wix3,代码行数:34,代码来源:BundleRunner.cs
示例16: IPCThread
static void IPCThread()
{
string pipeName = string.Format("bizhawk-pid-{0}-IPCKeyInput", System.Diagnostics.Process.GetCurrentProcess().Id);
for (; ; )
{
using (NamedPipeServerStream pipe = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024))
{
try
{
pipe.WaitForConnection();
BinaryReader br = new BinaryReader(pipe);
for (; ; )
{
int e = br.ReadInt32();
bool pressed = (e & 0x80000000) != 0;
lock (PendingEventList)
PendingEventList.Add(new KeyInput.KeyEvent { Key = (Key)(e & 0x7FFFFFFF), Pressed = pressed });
}
}
catch { }
}
}
}
开发者ID:henke37,项目名称:BizHawk,代码行数:27,代码来源:IPCKeyInput.cs
示例17: ListenForArguments
private void ListenForArguments(object state)
{
try
{
using (NamedPipeServerStream stream = new NamedPipeServerStream(this.identifier.ToString()))
{
using (StreamReader reader = new StreamReader(stream))
{
stream.WaitForConnection();
List<string> list = new List<string>();
while (stream.IsConnected)
{
list.Add(reader.ReadLine());
}
ThreadPool.QueueUserWorkItem(new WaitCallback(this.CallOnArgumentsReceived), list.ToArray());
}
}
}
catch (IOException)
{
}
finally
{
this.ListenForArguments(null);
}
}
开发者ID:afrog33k,项目名称:eAd,代码行数:26,代码来源:SingleInstance.cs
示例18: ProxyProcessManager
public ProxyProcessManager()
{
this.commandPipeName = String.Format(ProxyProcessManager.PIPE_NAME_FMT, Guid.NewGuid());
this.commandPipe = new NamedPipeServerStream(this.commandPipeName);
this.commandPipeReader = new BinaryReader(this.commandPipe);
this.commandPipeWriter = new BinaryWriter(this.commandPipe);
}
开发者ID:endurance,项目名称:dotnetexpect,代码行数:7,代码来源:ProxyProcessManager.cs
示例19: Worker
public void Worker()
{
while (true)
{
try
{
var serverStream = new NamedPipeServerStream("YetAnotherRelogger", PipeDirection.InOut, 100, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
serverStream.WaitForConnection();
ThreadPool.QueueUserWorkItem(state =>
{
using (var pipeClientConnection = (NamedPipeServerStream)state)
{
var handleClient = new HandleClient(pipeClientConnection);
handleClient.Start();
}
}, serverStream);
}
catch (Exception ex)
{
Logger.Instance.WriteGlobal(ex.Message);
}
Thread.Sleep(Program.Sleeptime);
}
}
开发者ID:Somebi,项目名称:YetAnotherRelogger,代码行数:26,代码来源:Communicator.cs
示例20: PipeServer
public PipeServer()
{
PipeName = string.Format("exTibiaS{0}", GameClient.Process.Id);
Pipe = new NamedPipeServerStream(PipeName, PipeDirection.InOut, -1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
OnReceive += new PipeListener(PipeServer_OnReceive);
Pipe.BeginWaitForConnection(new AsyncCallback(BeginWaitForConnection), null);
}
开发者ID:PimentelM,项目名称:extibiabot,代码行数:7,代码来源:PipeServer.cs
注:本文中的System.IO.Pipes.NamedPipeServerStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论