// ************************ // メンバーメソッド // --- 主となる処理(受付、受信、送信) // ************************ //============ // 受け付け処理用メソッド // クライアントからの接続の受け付けを、本メソッドを実行することで開始されます。 public void Listen(string Send_Data) { // 送信データー SendData = Send_Data; // 受付開始時に起動させるメソッドを実行 // (本クラスを利用する側のプログラムに、イベントを伝達 // するメソッドを実行) OnStartListen(DateTime.Now); try { // 名前付きパイプ操作用のオブジェクト(サーバー用)を生成 pipeServer = new System.IO.Pipes.NamedPipeServerStream("acsl-pipe", System.IO.Pipes.PipeDirection.InOut, 1, System.IO.Pipes.PipeTransmissionMode.Byte, System.IO.Pipes.PipeOptions.Asynchronous); // 接続待機 // クライアントが接続して来るのを待機する。 // かつ、その後の処理を行なうメソッドを指定。 pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer); } catch (Exception ex) { // エラー処理 System.Windows.Forms.MessageBox.Show(ex.Message, "エラー通知"); } }
private void CreatePipe() { m_PipeStream = new System.IO.Pipes.NamedPipeServerStream(m_Appname + "_Pipe", System.IO.Pipes.PipeDirection.In, 1, System.IO.Pipes.PipeTransmissionMode.Byte, System.IO.Pipes.PipeOptions.Asynchronous); m_AsyncResult = m_PipeStream.BeginWaitForConnection(new AsyncCallback(result => HandleConnection(result)), null); }
public EditorWorkProgressShowerInConsole() { #if UNITY_EDITOR_WIN var pipeName = System.DateTime.Now.ToString("yyMMddHHmmss"); var pipeout = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsole" + pipeName, System.IO.Pipes.PipeDirection.Out); var pipein = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsoleControl" + pipeName, System.IO.Pipes.PipeDirection.In); var arout = pipeout.BeginWaitForConnection(null, null); var arin = pipein.BeginWaitForConnection(null, null); var dir = Application.dataPath + "/../"; var tooldir = CapsModEditor.GetPackageOrModRoot(CapsEditorUtils.__MOD__) + "/~Tools~/"; System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(tooldir + "ProgressShowerInConsole.exe", pipeName); si.WorkingDirectory = tooldir; _ExProc = System.Diagnostics.Process.Start(si); var thd_Write = new System.Threading.Thread(() => { try { pipeout.EndWaitForConnection(arout); var sw = new System.IO.StreamWriter(pipeout); while (_MessageReady.WaitOne()) { _MessageReady.Reset(); lock (_MessageQueue) { foreach (var line in _MessageQueue) { sw.WriteLine(line); } sw.Flush(); _MessageQueue.Clear(); } } } finally { pipeout.Dispose(); } }); thd_Write.Start(); var thd_Read = new System.Threading.Thread(() => { try { pipein.EndWaitForConnection(arin); var sr = new System.IO.StreamReader(pipein); while (!_ExProc.HasExited) { var line = sr.ReadLine(); if (line != null) { if (line == "\uEE05Quit") { break; } } } } finally { _ShouldQuit = true; thd_Write.Abort(); _MessageReady.Set(); pipein.Dispose(); } }); thd_Read.Start(); #endif }