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


C# NamedPipeServerStream.WaitForConnection方法代碼示例

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


在下文中一共展示了NamedPipeServerStream.WaitForConnection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: ClientSendsByteServerReceives

    public static void ClientSendsByteServerReceives()
    {
        using (NamedPipeServerStream server = new NamedPipeServerStream("foo", PipeDirection.In))
        {
            byte[] sent = new byte[] { 123 };
            byte[] received = new byte[] { 0 };
            Task t = Task.Run(() =>
                {
                    using (NamedPipeClientStream client = new NamedPipeClientStream(".", "foo", PipeDirection.Out))
                    {
                        client.Connect();
                        Assert.True(client.IsConnected);

                        client.Write(sent, 0, 1);
                    }
                });
            server.WaitForConnection();
            Assert.True(server.IsConnected);

            int bytesReceived = server.Read(received, 0, 1);
            Assert.Equal(1, bytesReceived);

            t.Wait();
            Assert.Equal(sent[0], received[0]);
        }
    }
開發者ID:gitter-badger,項目名稱:corefx,代碼行數:26,代碼來源:NamedPipesSimpleTest.cs

示例3: StartServer

        private static void StartServer(Type interfaceType, Type implType, string pipeName)
        {
            //create the server
            var controller = new RpcController();
            
            var server = new RpcServer(controller);

            //register the service with the server. We must specify the interface explicitly since we did not use attributes
            server.GetType()
                  .GetMethod("RegisterService")
                  .MakeGenericMethod(interfaceType)
                  .Invoke(server, new[] {Activator.CreateInstance(implType)});

            //build the connection using named pipes
            try
            {
                pipeServerStreamIn = CreateNamedPipe(pipeName + "ctos", PipeDirection.In);
                pipeServerStreamOut = CreateNamedPipe(pipeName + "stoc", PipeDirection.Out);
                streamsCreated = true;
                pipeServerStreamIn.WaitForConnection();
                pipeServerStreamOut.WaitForConnection();
                
                //create and start the channel which will receive requests
                var channel = new StreamRpcChannel(controller, pipeServerStreamIn, pipeServerStreamOut, useSharedMemory: true);
                channel.Start();
            }
            catch (IOException e)
            {
                //swallow and exit
                Console.WriteLine("Something went wrong (pipes busy?), quitting: " + e);
                throw;
            }
        }
開發者ID:lishxi,項目名稱:_SharpMap,代碼行數:33,代碼來源:Program.cs

示例4: Run

        public void Run()
        {
            while (true)
            {
                var security = new PipeSecurity();
                security.SetAccessRule(new PipeAccessRule("Administrators", PipeAccessRights.FullControl, AccessControlType.Allow));

                using (pipeServer = new NamedPipeServerStream(
                    Config.PipeName,
                    PipeDirection.InOut,
                    NamedPipeServerStream.MaxAllowedServerInstances,
                    PipeTransmissionMode.Message,
                    PipeOptions.None,
                    Config.BufferSize, Config.BufferSize,
                    security,
                    HandleInheritability.None
                    ))
                {
                    try
                    {
                        Console.Write("Waiting...");
                        pipeServer.WaitForConnection();
                        Console.WriteLine("...Connected!");

                        if (THROTTLE_TIMER)
                        {
                            timer = new Timer
                            {
                                Interval = THROTTLE_DELAY,
                            };
                            timer.Elapsed += (sender, args) => SendMessage();
                            timer.Start();

                            while(pipeServer.IsConnected)Thread.Sleep(1);
                            timer.Stop();
                        }
                        else
                        {
                            while (true) SendMessage();
                        }
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                    }
                    finally
                    {
                        if (pipeServer != null)
                        {
                            Console.WriteLine("Cleaning up pipe server...");
                            pipeServer.Disconnect();
                            pipeServer.Close();
                            pipeServer = null;
                        }
                    }

                }

            }
        }
開發者ID:nathanchere,項目名稱:Spikes_JukeSaver,代碼行數:60,代碼來源:Server.cs

示例5: 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

示例6: 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();
			}
		}
開發者ID:ddugovic,項目名稱:RASuite,代碼行數:32,代碼來源:FilePiping.cs

示例7: Start

        public void Start()
        {
            try
            {
                ExtractUpdaterFromResource();

                using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("gsupdater", PipeDirection.Out))
                {
                    ExecuteUpdater();

                    pipeServer.WaitForConnection();

                    using (StreamWriter sw = new StreamWriter(pipeServer))
                    {
                        sw.AutoFlush = true;
                        sw.WriteLine(_sourcePath);
                        sw.WriteLine(_applicationPath);
                    }

                    Environment.Exit(0);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(@"Une erreur s'est produite lors du démarrage de la mise à jour de l'application"
                         + Environment.NewLine
                         + @"Detail du message :"
                         + Environment.NewLine
                         + e.Message);
            }
        }
開發者ID:ayassinov,項目名稱:GsUpdater,代碼行數:31,代碼來源:UpdateStarter.cs

示例8: Listen

        private static void Listen()
        {
            NamedPipeServerStream pipeServer =
                new NamedPipeServerStream(MyPipeName,
                                          PipeDirection.In,
                                          1,
                                          PipeTransmissionMode.Message,
                                          PipeOptions.None);

            StreamReader sr = new StreamReader(pipeServer);

            do
            {
                pipeServer.WaitForConnection();
                string fileName = sr.ReadLine();

                Console.WriteLine(fileName);

                Process proc = new Process();
                proc.StartInfo.FileName = fileName;
                proc.StartInfo.UseShellExecute = true;
                proc.Start();

                pipeServer.Disconnect();
            } while (true);
        }
開發者ID:baracchande,項目名稱:FileTagger,代碼行數:26,代碼來源:Program.cs

示例9: 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

示例10: 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

示例11: UserSignIn

        private void UserSignIn(string username, string password)
        {
            string hashed_password = sha256(password);
            MessageBox.Show(hashed_password);
            //send username and password to python and checks if correct
            string info = username + "#" + hashed_password;
            // Open the named pipe.

            var server = new NamedPipeServerStream("Communicate");
            server.WaitForConnection();     
            var br = new BinaryReader(server);
            var bw = new BinaryWriter(server); 
            send(bw, info);
            string message = recv(br); 
            server.Close();
            server.Dispose();

            //if receives true then send the user to the next gui.
            if (message == "1")
            {
                
                SaveFile form = new SaveFile();
                form.Show();

            }
            else
            {
                
                MessageBox.Show("incorrect password or username");
                this.Show();
            }
            
            
        }
開發者ID:Coby-Sonn,項目名稱:coby-s-project,代碼行數:34,代碼來源:Form1.cs

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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