Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using named pipes asynchronously with StreamWriter

I am trying to send a string over a named pipe using StreamWriter, but StreamWriter class only offers synchronous operations. I can use BeginWrite method of the NamedPipeServerStream class, but I wonder why there are no writer classes that would allow asynchronous operations. Am I missing something obvious?

like image 213
Lenik Avatar asked Nov 06 '22 10:11

Lenik


1 Answers

It would be significantly more complicated than for the raw streams. For the raw streams, any amount of data might come in asynchronously and the system just passes the buffer to you. The reader requires character encoding which may turn several bytes of raw data into a single Unicode character. Not that this would be impossible, the framework libraries just don't take it that far so you'll need to do this work yourself.

(Depending on your needs, creating another thread and performing the operations synchronously on it might make it easier to write your program. Note that scalability would be generally be higher when you use Begin/End async.)

like image 87
Jason Kresowaty Avatar answered Nov 14 '22 23:11

Jason Kresowaty