A pipeline is actually a piece of shared memory, which has two ends that are used for both process reads and writes. Here's how to implement pipeline communication between threads on Windows.
Reference Original: Multithreaded Pipe communication on Windows
C # multithreaded Pipeline communication
Create a Pipeline instance:
INTPTR pipe = PipeCommunication.Pipe.CreateNamedPipe (Pipe_name, (UINT) Pipecommunication.pi Peopenmodeflags.pipe_access_duplex, (UINT) (PipeCommunication.PipeModeFlags.PIPE_TYPE_BYTE | PipeCommunication.PipeModeFlags.PIPE_READMODE_BYTE), 1, 0, IntPtr.Zero);
Wait for the client to connect:
PipeCommunication.Pipe.ConnectNamedPipe (Pipe, ref nativeoverlapped);
Client Connection Pipeline Service side:
INTPTR pipe = PipeCommunication.Pipe.CreateFile (Pipe_name, (UINT) (Pipecommunication.desirem Ode. Generic_read | PipeCommunication.DesireMode.GENERIC_WRITE), 0, IntPtr.Zero, 3, IntPtr.Zero);
Read and write data between threads:
Service side
PipeCommunication.Pipe.WriteFile (pipe, bytes, (UINT) (sizeof (byte) * bytes. Length), byteswrittenorred, ref nativeoverlapped); try { while ( VALUE&NBSP;<&NBSP;10) { //omit to Clear bytes pipecommunication.pipe.readfile (Pipe, bytes, (UINT) (sizeof (byte) * bytes. Length), byteswrittenorred, ref nativeoverlapped); value = Bitconverter.toint32 (bytes, 0); value++; bytes = bitconverter.getbytes ( Value); thread.sleep (; ) pipecommunication.pipe.writefile (pipe, bytes, (UINT) (sizeof (byte) * bytes. Length), byteswrittenorred, ref nativeoverlapped); } }
Client
try { while (value < 10) { //omit to Clear bytes pipecommunication.pipe.readfile (pipe, bytes, (UINT) (sizeof (byte) * bytes. Length), byteswrittenorred, ref nativeoverlapped); value = Bitconverter.toint32 (bytes, 0); value++; bytes = bitconverter.getbytes (value); thread.sleep (; ) pipecommunication.pipe.writefile (pipe, bytes, (UINT) (sizeof (byte ) * bytes. Length), byteswrittenorred, ref nativeoverlapped); } }
Source
Https://github.com/DynamsoftRD/windows-pipe-communication
git clone https://github.com/DynamsoftRD/windows-pipe-communication.git
Reference
Pipes
Multi-threaded pipeline communication on windows