using System; using System.IO.Pipes; using System.Text; using System.Threading; namespace ArchestrAServices.Common.Resolution; public class PipeServer : IDisposable { private string _pipeName; private NamedPipeServerStream _pipeServer; private bool disposed; public PipeServer(string PipeName) { _pipeName = PipeName; _pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.In, 1, PipeTransmissionMode.Message); } public string ReadString() { _pipeServer.WaitForConnection(); string result = string.Empty; if (_pipeServer.IsConnected) { while (!_pipeServer.IsMessageComplete) { Thread.Sleep(50); } byte[] array = new byte[100]; int num = _pipeServer.Read(array, 0, 100); if (num > 0) { result = Encoding.UTF8.GetString(array, 0, num); } } return result; } public void Dispose() { Dispose(freeManagedObjectsAlso: true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool freeManagedObjectsAlso) { if (!disposed) { if (freeManagedObjectsAlso) { _pipeServer.Dispose(); } disposed = true; } } ~PipeServer() { Dispose(freeManagedObjectsAlso: false); } }