當前位置: 首頁>>代碼示例>>C#>>正文


C# Pipes.NamedPipeServerStream類代碼示例

本文整理匯總了C#中System.IO.Pipes.NamedPipeServerStream的典型用法代碼示例。如果您正苦於以下問題:C# NamedPipeServerStream類的具體用法?C# NamedPipeServerStream怎麽用?C# NamedPipeServerStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NamedPipeServerStream類屬於System.IO.Pipes命名空間,在下文中一共展示了NamedPipeServerStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的System.IO.Pipes.NamedPipeServerStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。