C# communication between processes

元气小坏坏 提交于 2019-12-05 07:07:36

The answer is simple;

Since you can import any DLL into the script you may create a custom DLL that will implement communication between the processes in any way you desire: shared memory, named pipe, TCP/UDP.

Your method of interprocess communication should depend on how important it is that each message get processed.

For instance, if process A tells process B to, say, send an email to your IT staff saying that a server is down, it's pretty important.

If however you're streaming audio, individual messages (packets) aren't critical to the performance of the app, and can be dropped.

If the former, you should consider using persistent storage such as a database to store messages, and let each process poll the database to retrieve its own messages. In this way, if a process is terminated or loses communication with the other processes temporarily, it will be able to retrieve whatever messages it has missed when it starts up again.

You could use a form of Interprocess Communication, even within the same process. Treat your scripts as separate processes, and communicate that way.

Named pipes could be a good option in this situation. They are very fast, and fairly easy to use in .NET 3.5.

Alternatively, if the scripts are loaded into a single AppDomain, you could use a static class or singleton as a communication service. However, if the scripts get loaded in isolation, this may not be possible.

Well, not knowing the details of your environment, there is not much I can really offer. You are using the term "C# scripts"...I am not exactly sure what that means, as C# is generally a compiled language.

If you are using normal C#, have you looked into WCF with Named Pipes? If your assemblies are running on the same physical machine, you should be able to easily and quickly create some WCF services hosted with the Named Pipe binding. Named pipes provide a simple, efficient, and quick message transfer mechanism in a local context. WCF itself is pretty easy to use, and is a native component of the .NET framework.

Since you already have the File I/O in place you might get enough speed by placing it on a RAM disk. If you are polling for changes today a FileSystemWatcher could help to get your communication more responsive.

You can use PipeStream. Which are fast than disk IO as they are done using main memory.

XMPP/Jabber is another appraoch take a look at jabber.net.

Another easy way is to open a TCP Socket on a predefined Port, connect to it from the other process and communicate that way.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!