How to exchange data between two process? [duplicate]
Asked Answered
H

4

7

Possible Duplicate:
IPC Mechanisms in C# - Usage and Best Practices

I have two diffenent process: A and B.

The process A wants to send to the process B some data (array of bytes, strings, structures, etc...). So suppose A need to send the following buffer:

var buffer = new byte[100].
SendToAnotherProcess(B, buffer);

And B need to receive this buffer:

byte[] buffer;
ReceiveFromAnotherProcess(A, out buffer);

What is the easiest solution to do this?

Holliholliday answered 30/11, 2012 at 10:15 Comment(1)
Google "windows interprocess communication".Devoice
C
7

You can use Named Pipe. If it is C# 4.0 and above, you can also use Memory mapped file

Chukar answered 30/11, 2012 at 10:20 Comment(1)
+1 for the named pipe. Using memory mapped files can be troublesome if not implemented properly.Yerga
D
2

There's a multitude of options. To name a few low-level IPC mechanisms:

  • named pipes
  • shared memory
  • TCP/IP sockets

Also, there are some higher-level options:

  • .NET Remoting
  • WCF
Devoice answered 30/11, 2012 at 10:18 Comment(0)
T
0

One common way is to use files to communicate between the processed.

Each can write to a specific file that the other reads from.

You can use WCF, the registry, network interface, message queues or any other mechanism that lives outside the process.

Terricolous answered 30/11, 2012 at 10:18 Comment(3)
The registry as an IPC mechanism. That's pretty dire.Rayerayfield
@DavidHeffernan - Seen it before...Terricolous
Ah, now you mention WCF. That's a bit more like it.Rayerayfield
G
0

There is some special instrument in .net:

.Net Remoting

WCF

Gurdwara answered 30/11, 2012 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.