当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeServerStream.EndWaitForConnection方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.EndWaitForConnection方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.EndWaitForConnection方法的具体用法?C# NamedPipeServerStream.EndWaitForConnection怎么用?C# NamedPipeServerStream.EndWaitForConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeServerStream的用法示例。


在下文中一共展示了NamedPipeServerStream.EndWaitForConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PipeServerAsyncEnumerator

		private static IEnumerator<Int32> PipeServerAsyncEnumerator(AsyncEnumerator ae) {
			// Each server object performs asynchronous operation on this pipe
			using (var pipe = new NamedPipeServerStream(
				"Echo", PipeDirection.InOut, -1, PipeTransmissionMode.Message,
				PipeOptions.Asynchronous | PipeOptions.WriteThrough)) {
				// Asynchronously accept a client connection
				pipe.BeginWaitForConnection(ae.End(), null);
				yield return 1;

				// A client connected, let's accept another client
				var aeNewClient = new AsyncEnumerator();
				aeNewClient.BeginExecute(PipeServerAsyncEnumerator(aeNewClient),
					aeNewClient.EndExecute);

				// Accept the client connection
				pipe.EndWaitForConnection(ae.DequeueAsyncResult());

				// Asynchronously read a request from the client
				Byte[] data = new Byte[1000];
				pipe.BeginRead(data, 0, data.Length, ae.End(), null);
				yield return 1;

				// The client sent us a request, process it
				Int32 bytesRead = pipe.EndRead(ae.DequeueAsyncResult());

				// Just change to upper case
				data = Encoding.UTF8.GetBytes(
					Encoding.UTF8.GetString(data, 0, bytesRead).ToUpper().ToCharArray());

				// Asynchronously send the response back to the client
				pipe.BeginWrite(data, 0, data.Length, ae.End(), null);
				yield return 1;

				// The response was sent to the client, close our side of the connection
				pipe.EndWrite(ae.DequeueAsyncResult());
			} // Close happens in a finally block now!
		}
开发者ID:Helen1987,项目名称:edu,代码行数:37,代码来源:PipeServerLib.cs

示例2: SendMessageAsync

        public async void SendMessageAsync()
        {
            try
            {
                using (var pipe = new NamedPipeServerStream(verb, PipeDirection.Out, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous))
                using (var stream = new StreamWriter(pipe))
                {
                    var connectionTask = Task.Factory.FromAsync(pipe.BeginWaitForConnection, pipe.EndWaitForConnection, null);
                    var timeoutTask = Task.Delay(2000);
                    var firstTask = await Task.WhenAny(connectionTask, timeoutTask);
                    if (firstTask == timeoutTask)
                    {
                        pipe.EndWaitForConnection(connectionTask);
                        return;
                    }

                    stream.AutoFlush = true;
                    await stream.WriteLineAsync(selectedFile);
                }
            }
            catch (Exception exception)
            {
                //OnSendMessageException(pipeName, new MessengerExceptionEventArgs(exception));
            }
        }
开发者ID:jeffgriffin,项目名称:ChromiumBackground,代码行数:25,代码来源:FileContextMenuExt.cs

示例3: ServerLoop

 private void ServerLoop()
 {
     while (_stopRequired)
     {
         _allDone.Reset();
         var pipeStream = new NamedPipeServerStream(PipeName, PipeDirection.InOut, -1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);                
         pipeStream.BeginWaitForConnection(asyncResult =>
                                               {                                                          
                                                   pipeStream.EndWaitForConnection(asyncResult);
                                                   _allDone.Set();
                                                   var thread = new Thread(ProcessClientThread);
                                                   thread.Start(pipeStream);
                                               }, null);
         _allDone.WaitOne();
     }
 }
开发者ID:webbers,项目名称:dongle.net,代码行数:16,代码来源:PipeServer.cs

示例4: SetupPipeWait

		static void SetupPipeWait(App app)
		{
			var pipe = new NamedPipeServerStream(IPCName, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
			pipe.BeginWaitForConnection(result =>
			{
				pipe.EndWaitForConnection(result);

				var buf = new byte[sizeof(int)];
				pipe.Read(buf, 0, buf.Length);
				var len = BitConverter.ToInt32(buf, 0);
				buf = new byte[len];
				pipe.Read(buf, 0, buf.Length);
				var commandLine = Coder.BytesToString(buf, Coder.CodePage.UTF8);

				app.Dispatcher.Invoke(() => app.CreateWindowsFromArgs(commandLine));

				SetupPipeWait(app);
			}, null);
		}
开发者ID:xyandro,项目名称:NeoEdit,代码行数:19,代码来源:InstanceManager.cs

示例5: pipeServerThread

        void pipeServerThread(object o)
        {
            NamedPipeServerStream pipeServer = null;
            try
            {
                while (true)
                {
                    pipeServer = new NamedPipeServerStream(
                        this.ServerName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

                    IAsyncResult async = pipeServer.BeginWaitForConnection(null, null);
                    int index = WaitHandle.WaitAny(new WaitHandle[] { async.AsyncWaitHandle, closeApplicationEvent });
                    switch (index)
                    {
                        case 0:
                            pipeServer.EndWaitForConnection(async);
                            using (StreamReader sr = new StreamReader(pipeServer))
                            using (StreamWriter sw = new StreamWriter(pipeServer))
                            {
                                this.Recived(this, new ServerReciveEventArgs(sr, sw));
                            }
                            if (pipeServer.IsConnected)
                            {
                                pipeServer.Disconnect();
                            }
                            break;
                        case 1:
                            return;
                    }
                }
            }
            finally
            {
                if (pipeServer != null)
                {
                    pipeServer.Close();
                }
            }
        }
开发者ID:omega227,项目名称:DeanCC,代码行数:39,代码来源:IPCServer.cs

示例6: LaunchProcessAndSendDto

        /// <summary>
        /// Launches the specifies process and sends the dto object to it using a named pipe
        /// </summary>
        /// <param name="dto">Dto object to send</param>
        /// <param name="processStartInfo">Process info for the process to start</param>
        /// <param name="syncProcessName">Name of the pipe to write to</param>
        /// <returns>The started process</returns>
        public static Process LaunchProcessAndSendDto(NauDto dto, ProcessStartInfo processStartInfo, string syncProcessName)
        {
            Process p;

            using (NamedPipeServerStream pipe = new NamedPipeServerStream(syncProcessName, PipeDirection.Out, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous))
            {
                p = Process.Start(processStartInfo);

                if (p == null)
                {
                    throw new ProcessStartFailedException("The process failed to start");
                }

                var asyncResult = pipe.BeginWaitForConnection(null, null);

                if (asyncResult.AsyncWaitHandle.WaitOne(PIPE_TIMEOUT))
                {
                    pipe.EndWaitForConnection(asyncResult);

                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(pipe, dto);
                }
                else if (p.HasExited)
                {
                    Type exceptionType = Marshal.GetExceptionForHR(p.ExitCode).GetType();

                    throw new TimeoutException(string.Format("The NamedPipeServerStream timed out waiting for a named pipe connection, " +
                        "but the process has exited with exit code: {0} ({1})", p.ExitCode, exceptionType.FullName));
                }
                else
                {
                    throw new TimeoutException("The NamedPipeServerStream timed out waiting for a named pipe connection.");
                }
            }

            return p;
        }
开发者ID:synhershko,项目名称:NAppUpdate,代码行数:44,代码来源:NauIpc.cs

示例7: ShellCommandHandler

 public ShellCommandHandler(CommandHandler cmdHandler)
 {
     pipeServer = new NamedPipeServerStream("sciGitPipe", PipeDirection.In, 1, PipeTransmissionMode.Byte,
                                      PipeOptions.Asynchronous);
       pipeThread = new Thread(() => {
     while (true) {
       try {
     var ar = pipeServer.BeginWaitForConnection(null, null);
     pipeServer.EndWaitForConnection(ar);
     var ss = new StreamString(pipeServer);
     string verb = ss.ReadString();
     string filename = ss.ReadString();
     cmdHandler(verb, filename);
     pipeServer.Disconnect();
       } catch (ObjectDisposedException) {
     break;
       } catch (IOException) {
     break;
       } catch (Exception e) {
     Logger.LogException(e);
       }
     }
       });
 }
开发者ID:SciGit,项目名称:scigit-client,代码行数:24,代码来源:ShellCommandHandler.cs

示例8: Initialize

        public void Initialize()
        {
            if (initialized)
                return;
            else
                initialized = true;

            // 初始化RenderControl
            KillExistingProcess();

            // 启动Pipe
            // NOTE 必须设置 Asynchronous
            pipeServer = new NamedPipeServerStream(
                "testpipe",
                PipeDirection.InOut,
                1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
            inBuffer = new byte[1024];

            LogManager.Instance.Log("开始异步等待管道连接");
            pipeServer.BeginWaitForConnection(ar =>
            {
                pipeServer.EndWaitForConnection(ar);
                LogManager.Instance.Log("管道已连接");
                pipeServer.BeginRead(inBuffer, 0, pipeServer.InBufferSize, onClientDataReceived, pipeServer);
            }, pipeServer);

            // ProcessStartInfo info = new ProcessStartInfo(ConfigManager.Instance.Get("RenderAppPath"));
            ProcessStartInfo info = new ProcessStartInfo(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "./SpineRenderer/SpineRenderer.exe"));
            info.UseShellExecute = true;
            info.Arguments = " -popupwindow";
            
            // NOTE Hidden 会造成没有窗口句柄 unityProcess.MainWindowHandle == IntPtr.Zero
            // info.WindowStyle = ProcessWindowStyle.Minimized;
            // info.WindowStyle = ProcessWindowStyle.Normal;
            // info.WindowStyle = ProcessWindowStyle.Hidden;
            renderAppProcess = System.Diagnostics.Process.Start(info);

            // Wait for process to be created and enter idle condition
            LogManager.Instance.Log("开始等待渲染程序空闲");

            // NOTE thy 方法A在Win7上不管用,方法B在Win7/Win8上都OK
            // WaitForInputIdle 并不保证窗口句柄准备好

            // 方法-A
            // renderAppProcess.WaitForInputIdle(5000);

            // 方法-B
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            while (renderAppProcess.MainWindowHandle == IntPtr.Zero)
            {
                System.Threading.Thread.Sleep(100);
                // stopWatch.ElapsedMilliseconds > 
            }

            if (renderAppProcess.HasExited)
            {
                LogManager.Instance.Warn("内嵌程序已经退出");
            }
            else
            {
                LogManager.Instance.Log("内嵌程序初始化完成");
                LogManager.Instance.Log("检查内嵌程序句柄是否存在: " + renderAppProcess.MainWindowHandle.ToString());
            }
        }
开发者ID:Henry-T,项目名称:UnityPG,代码行数:65,代码来源:RenderAppManager.cs

示例9: 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;
        }
开发者ID:sbruyere,项目名称:SqlBcpWrapper,代码行数:29,代码来源:SqlBcpWrapper.cs

示例10: Init

 /// <summary>
 /// Initialises the named pipe server and waits for a connection
 /// </summary>
 /// <param name="pipe">The name of the pipe to create</param>
 /// <returns>True if a connection is received. Otherwise false.</returns>
 public bool Init(string pipe)
 {
     bool OK = Disconnect();
     if (OK)
     {
         try
         {
             ThePipe = new NamedPipeServerStream(pipe, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
             ThePipe.ReadMode = PipeTransmissionMode.Byte;
             ThePipe.BeginWaitForConnection(new AsyncCallback(delegate(IAsyncResult result)
             {
                 try
                 {
                     ThePipe.EndWaitForConnection(result);
                     
                     if (OnConnected != null)
                     {
                         OnConnected();
                     }
                 }
                 catch
                 {
                     //Ignore as probably error while terminating
                 }
             }), null);
         }
         catch
         {
             OK = false;
             ThePipe = null;
         }
     }
     return OK;
 }
开发者ID:rmhasan,项目名称:FlingOS,代码行数:39,代码来源:Serial.cs

示例11: ReadNamedPipeAsync

        private async Task ReadNamedPipeAsync()
        {
            string pipeID = pID.ToString();

            using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("luaPipeR" + pipeID, PipeDirection.In, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous))
            {
                await Task.Factory.FromAsync((cb, state) => pipeServer.BeginWaitForConnection(cb, state), ar => pipeServer.EndWaitForConnection(ar), null);

                using (StreamReader pipeReader = new StreamReader(pipeServer))
                {
                    await TaskScheduler.Default;

                    while (this.keepReadPipeOpen)
                    {
                        string command = await pipeReader.ReadLineAsync();

                        switch (command)
                        {
                            case "BreakpointHit":
                            {
                                debugThread.SourceFile = await pipeReader.ReadLineAsync();
                                debugThread.Line = uint.Parse(await pipeReader.ReadLineAsync());
                                debugThread.FuncName = await pipeReader.ReadLineAsync();

                                // Receive Callstack
                                debugThread.FrameCount = int.Parse(await pipeReader.ReadLineAsync());

                                List<Frame> frames = new List<Frame>(debugThread.FrameCount);

                                for (int stackLineIndex = 0; stackLineIndex < debugThread.FrameCount; stackLineIndex++)
                                {
                                    string func = await pipeReader.ReadLineAsync();
                                    string source = await pipeReader.ReadLineAsync();
                                    string line = await pipeReader.ReadLineAsync();
                                    frames.Add(new Frame(func, source, line));
                                }

                                debugThread.StackFrames = frames;
                                    
                                int numberToRead = int.Parse(await pipeReader.ReadLineAsync());

                                List<Variable> variables = new List<Variable>(numberToRead);

                                for (int localIndex = 0; localIndex < numberToRead; localIndex++)
                                {
                                    variables.Add(new Variable(await pipeReader.ReadLineAsync(), await pipeReader.ReadLineAsync(), await pipeReader.ReadLineAsync()));
                                }

                                debugThread.NumberOfLocals = numberToRead;
                                debugThread.Locals = variables;
                                AD7BreakpointEvent.Send(this, breakpointManager.GetBoundBreakpoint(debugThread.SourceFile + debugThread.Line));
                                break;
                            }
                            case "BreakpointBound":
                                string fileandline = await pipeReader.ReadLineAsync();
                                AD7BoundBreakpoint boundbp = breakpointManager.GetBoundBreakpoint(fileandline);

                                AD7BreakpointBoundEvent boundBreakpointEvent = new AD7BreakpointBoundEvent(boundbp);
                                Send(boundBreakpointEvent, AD7BreakpointBoundEvent.IID, this);
                                break;
                            case "StepComplete":
                            {
                                debugThread.FrameCount = 1;
                                debugThread.SourceFile = await pipeReader.ReadLineAsync();
                                debugThread.Line = uint.Parse(await pipeReader.ReadLineAsync());
                                debugThread.FuncName = await pipeReader.ReadLineAsync();

                                // Receive Callstack
                                debugThread.FrameCount = int.Parse(await pipeReader.ReadLineAsync());

                                List<Frame> frames = new List<Frame>(debugThread.FrameCount);

                                for (int stackLineIndex = 0; stackLineIndex < debugThread.FrameCount; stackLineIndex++)
                                {
                                    string func = await pipeReader.ReadLineAsync();
                                    string source = await pipeReader.ReadLineAsync();
                                    string line = await pipeReader.ReadLineAsync();
                                    frames.Add(new Frame(func, source, line));
                                }

                                debugThread.StackFrames = frames;
                                    
                                int numberToRead = int.Parse(await pipeReader.ReadLineAsync());

                                List<Variable> variables = new List<Variable>(numberToRead);

                                for (int localIndex = 0; localIndex < numberToRead; localIndex++)
                                {
                                    variables.Add(new Variable(await pipeReader.ReadLineAsync(), await pipeReader.ReadLineAsync(), await pipeReader.ReadLineAsync()));
                                }

                                debugThread.NumberOfLocals = numberToRead;
                                debugThread.Locals = variables;


                                Send(new AD7StepCompleteEvent(), AD7StepCompleteEvent.IID, this);
                                break;
                            }
                        }
                    }
//.........这里部分代码省略.........
开发者ID:e42s,项目名称:VSLua,代码行数:101,代码来源:AD7Engine.cs

示例12: waitForAdditionalInstances

    private void waitForAdditionalInstances(string[] args)
    {
        var accumulatedArgs = new List<string>(args);

        while (true)
        {
            var signal = new ManualResetEvent(false);
            using (var pipeServer = new NamedPipeServerStream(ipcNamedPipeGuid, PipeDirection.In, -1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
            {
                pipeServer.BeginWaitForConnection(x =>
                {
                    // if timed out, stop waiting for a connection
                    if (signal.WaitOne(0))
                    {
                        signal.Close();
                        return;
                    }

                    pipeServer.EndWaitForConnection(x);
                    signal.Set();
                }, null);

                // no client connected to the pipe within the Timeout period
                if (!signal.WaitOne(Timeout, true))
                {
                    signal.Set();
                    break;
                }

                using (var sr = new StreamReader(pipeServer))
                {
                    int length = Convert.ToInt32(sr.ReadLine());
                    for (int i = 0; i < length; ++i)
                        accumulatedArgs.Add(sr.ReadLine());
                }
            }

            // new args have been added to accumulatedArgs, continue loop to listen for another client
        }

        ipcMutex.Close();
        Launching(this, new SingleInstanceEventArgs(accumulatedArgs.ToArray()));
    }
开发者ID:lgatto,项目名称:proteowizard,代码行数:43,代码来源:SingleInstanceHandler.cs

示例13: OutOfProcessBuild

        private static BuildResult OutOfProcessBuild (Dictionary<string, object> arguments, int startupTimeoutMs = 5000) {
            var jss = new JavaScriptSerializer {
                MaxJsonLength = 1024 * 1024 * 64
            };

            var argsJson = jss.Serialize(arguments);
            var pipeId = String.Format("JSIL.Build{0:X4}", (new Random()).Next());

            Console.Error.WriteLine("// Starting out-of-process solution build with ID '{0}'...", pipeId);

            using (var pipe = new NamedPipeServerStream(
                pipeId, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous
            )) {
                var psi = new ProcessStartInfo {
                    FileName = Process.GetCurrentProcess().MainModule.FileName,
                    Arguments = String.Format("--buildSolution {0}", pipeId),
                    WorkingDirectory = Environment.CurrentDirectory,
                    CreateNoWindow = false,
                    UseShellExecute = false,
                    ErrorDialog = false                    
                };
                var childProcess = Process.Start(psi);
                if (childProcess == null)
                    throw new InvalidOperationException("Failed to start child process");

                var connectedEvent = new ManualResetEventSlim(false);
                var exitedEvent = new ManualResetEventSlim(false);

                try {
                    var connectAR = pipe.BeginWaitForConnection((_) => connectedEvent.Set(), null);

                    try {
                        childProcess.Exited += (s, e) => exitedEvent.Set();
                        if (childProcess.HasExited)
                            exitedEvent.Set();
                    } catch {
                    }

                    WaitHandle.WaitAny(
                        new[] { connectedEvent.WaitHandle, exitedEvent.WaitHandle }, startupTimeoutMs
                    );

                    if (connectedEvent.IsSet) {
                        pipe.EndWaitForConnection(connectAR);
                    } else if (exitedEvent.IsSet) {
                        Console.Error.WriteLine("// Out-of-process solution build terminated unexpectedly with code {0}!", childProcess.ExitCode);
                        Environment.Exit(1);
                    } else {
                        Console.Error.WriteLine("// Out-of-process solution build timed out!");
                        Environment.Exit(2);
                    }

                    using (var sr = new StreamReader(pipe))
                    using (var sw = new StreamWriter(pipe)) {
                        sw.WriteLine(argsJson);
                        sw.Flush();
                        pipe.Flush();
                        pipe.WaitForPipeDrain();

                        var resultJson = sr.ReadLine();
                        var buildResult = jss.Deserialize<BuildResult>(resultJson);

                        Console.Error.WriteLine("// Out-of-process solution build completed successfully.");

                        return buildResult;
                    }
                } finally {
                    try {
                        if (!childProcess.HasExited)
                            childProcess.Kill();
                    } catch {
                    }

                    childProcess.Dispose();
                }
            }
        }
开发者ID:sq,项目名称:JSIL,代码行数:77,代码来源:SolutionBuilder.cs

示例14: StartServer

        public bool StartServer(string strEventName, string strPipeName, Action<CMD_STREAM, CMD_STREAM> pfnCmdProc)
        {
            if (pfnCmdProc == null || strEventName.Length == 0 || strPipeName.Length == 0)
            {
                return false;
            }
            if (m_ServerThread != null)
            {
                return false;
            }

            m_StopFlag = false;
            m_PulseEvent = new AutoResetEvent(false);
            m_ServerThread = new Thread(new ThreadStart(() =>
            {
                using (EventWaitHandle eventConnect = new EventWaitHandle(false, EventResetMode.AutoReset, strEventName))
                using (NamedPipeServerStream pipe = new NamedPipeServerStream(
                           strPipeName.Substring(strPipeName.StartsWith("\\\\.\\pipe\\", StringComparison.OrdinalIgnoreCase) ? 9 : 0),
                           PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
                {
                    while (m_StopFlag == false)
                    {
                        pipe.BeginWaitForConnection(asyncResult =>
                        {
                            try
                            {
                                if (m_StopFlag == false)
                                {
                                    pipe.EndWaitForConnection(asyncResult);
                                    m_PulseEvent.Set();
                                }
                            }
                            catch (ObjectDisposedException)
                            {
                            }
                        }, null);
                        eventConnect.Set();
                        m_PulseEvent.WaitOne();
                        if (pipe.IsConnected)
                        {
                            try
                            {
                                byte[] bHead = new byte[8];
                                if (pipe.Read(bHead, 0, 8) == 8)
                                {
                                    CMD_STREAM stCmd = new CMD_STREAM();
                                    stCmd.uiParam = BitConverter.ToUInt32(bHead, 0);
                                    stCmd.uiSize = BitConverter.ToUInt32(bHead, 4);
                                    stCmd.bData = stCmd.uiSize == 0 ? null : new byte[stCmd.uiSize];
                                    if (stCmd.uiSize == 0 || pipe.Read(stCmd.bData, 0, stCmd.bData.Length) == stCmd.bData.Length)
                                    {
                                        CMD_STREAM stRes = new CMD_STREAM();
                                        pfnCmdProc.Invoke(stCmd, stRes);
                                        if (stRes.uiParam == (uint)ErrCode.CMD_NEXT)
                                        {
                                            // Emun用の繰り返しは対応しない
                                            throw new InvalidOperationException();
                                        }
                                        else if (stRes.uiParam != (uint)ErrCode.CMD_NO_RES)
                                        {
                                            BitConverter.GetBytes(stRes.uiParam).CopyTo(bHead, 0);
                                            BitConverter.GetBytes(stRes.uiSize).CopyTo(bHead, 4);
                                            pipe.Write(bHead, 0, 8);
                                            if (stRes.uiSize != 0 && stRes.bData != null && stRes.bData.Length >= stRes.uiSize)
                                            {
                                                pipe.Write(stRes.bData, 0, (int)stRes.uiSize);
                                            }
                                        }
                                    }
                                }
                                pipe.WaitForPipeDrain();
                                pipe.Disconnect();
                            }
                            catch
                            {
                                // Read & Write 中に切断されると例外が起きるはずなので一応 catch しておく
                            }
                        }
                    }
                }
            }));
            m_ServerThread.Start();

            return true;
        }
开发者ID:nekopanda,项目名称:EDCB,代码行数:85,代码来源:PipeServer.cs

示例15: CreateAsync

            public override async Task<IAsyncTransport> CreateAsync(Address address)
            {
                NamedPipeServerStream server = new NamedPipeServerStream(address.Path, PipeDirection.InOut, 4,
                    PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
#if DOTNET
                await server.WaitForConnectionAsync();
#else
                await Task.Factory.FromAsync(
                    (c, s) => server.BeginWaitForConnection(c, s),
                    (r) => server.EndWaitForConnection(r),
                    null);
#endif
                return new NamedPipeTransport(server);
            }
开发者ID:ChugR,项目名称:amqpnetlite,代码行数:14,代码来源:NamedPipeTransport.cs


注:本文中的System.IO.Pipes.NamedPipeServerStream.EndWaitForConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。