0
Мне нужно держать PipeStrem открытым и не закрывать его, то есть избавиться от использования. Я пытался держать его открытым, но получить Exception Cannot Access closed strem
Как я могу его решить? Это мой код прямо сейчас:Как я могу открыть PipeSteam?
public static void StartServer()
{
//NamedPipeServerStream pipeStream = new NamedPipeServerStream("PipeTo" + Process.GetCurrentProcess().Id.ToString());
while(true)
{
using (NamedPipeServerStream pipeStream = new NamedPipeServerStream("PipeTo" + Process.GetCurrentProcess().Id.ToString()))
{
Console.WriteLine("[Server] Pipe Created, the current process ID is {0};\n[Server] The current process name is {1}", Process.GetCurrentProcess().Id.ToString(), Process.GetCurrentProcess().ProcessName);
try { pipeStream.WaitForConnection(); }
catch
{
_worker = new BackgroundWorker();
_worker.DoWork += _worker_DoWork;
}
Console.WriteLine("[Server] Connected Successfully");
using (StreamReader sr = new StreamReader(pipeStream))
{
string pathToExe = string.Empty;
while ((pathToExe = sr.ReadLine()) != null)
{
Process.Start(pathToExe);
}
}
}
}
}