i need keep pipestrem open , not close it, i.e. rid off using. tried keep open, exception cannot access closed strem how can solve it? code now:
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, current process id {0};\n[server] current process name {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); } } } } }
using on either stream itself, or streamreader cause close.
for more information: does disposing streamreader close stream?
Comments
Post a Comment