当前位置: 首页>>代码示例>>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;未经允许,请勿转载。