简体   繁体   English

在.NET Windows窗体中,如何在两个EXE或应用程序之间发送数据?

[英]In .NET Windows Forms, how can I send data between two EXEs or applications?

The scenario that I bring forward is basically that of, interaction between two .NET executables. 我提出的场景基本上就是两个.NET可执行文件之间的交互。

I have made a .NET Windows Forms application in C# (Application-A) that runs on a user's machine and does some specific activity, due to which it collects some data. 我已经制作了一个用C#开发的.NET Windows窗体应用程序(Application-A),该应用程序在用户的计算机上运行,​​并执行一些特定的活动,因此它收集了一些数据。 Now I have another .NET Windows Forms executable (Application-B), also made in C#, which also does some specific activity based certain inputs or data provided. 现在,我还有另一个.NET Windows Forms可执行文件(Application-B),它也是用C#编写的,它也根据提供的某些输入或数据执行一些特定的活动。

Now what I want to do here is, call Application-B from the Application-A and pass the some data to it. 现在我要在这里做的是,从Application-A调用Application-B并将一些数据传递给它。

How do I accomplish this? 我该如何完成?

You can use several options. 您可以使用几个选项。 You have some resources for each option below. 下面的每个选项都有一些资源。

  • .NET Remoting .NET远程处理
  • WCF WCF
  • Use a communication file 使用通讯文件
  • MSMQ MSMQ

Two last options are valid only if the processes are in the same machine. 仅当进程在同一台计算机上时,后两个选项才有效。

Since they are two separated processes I think that the easiest way to do this is using .NET Remoting . 由于它们是两个独立的进程,因此我认为最简单的方法是使用.NET Remoting Here you can find documentation and examples about how to do it. 在这里,您可以找到有关此操作的文档和示例。

An alternative to Remoting is WCF (>= .NET 3.0). 远程处理的替代方法是WCF (> = .NET 3.0)。 It performs better than remoting. 它比远程处理要好

If the processes will be always in the same machine, if you don't want to use remoting on localhost you can communicate them through a file ( simple solutions usually work fine! ) 如果进程始终在同一台机器上,并且不想在本地主机上使用远程处理,则可以通过文件进行通信( 简单的解决方案通常可以正常工作!

And other more complex solution is communicate them using a Message Queue ( MSMQ ). 其他更复杂的解决方案是使用消息队列( MSMQ )进行通信。 Here you cand find out an example about how to use it. 在这里,您可以找到有关如何使用它的示例。

You can use MSMQ to communicate between the applications. 您可以使用MSMQ在应用程序之间进行通信。

Any mechanism will do, however. 但是,任何机制都可以。

You could use file based communications (write to a known directory and read from it). 您可以使用基于文件的通信(写入已知目录并从中读取)。

WCF is another solution. WCF是另一种解决方案。

If both the applications are running on same user computer than 如果两个应用程序都在同一用户计算机上运行,​​则

1- this can be achieved through inter-process communications channel (IPC channel) 1-这可以通过进程间通信通道(IPC通道)来实现

2- If you are using .NET 4.0, you can use memory mapped files 2-如果使用的是.NET 4.0,则可以使用内存映射文件

If both the applications are running on different system 如果两个应用程序都在不同的系统上运行

1- You can make use of .NET Remoting 1-您可以利用.NET Remoting

2- You can have WCF service based communication 2-您可以进行基于WCF服务的通信

3- Web Service is also an option if using .NET 2.0 or lower versions 3-如果使用.NET 2.0或更低版本,Web Service也是一个选项

WCF is going to allow you a lot of flexibility in the future : Should you ever decide to enhance this communication to support multiple modes of communication, app.config changes should be the majority of the work to support a different binding. WCF将来将为您提供很大的灵活性:如果您决定增强此通信以支持多种通信方式,则app.config更改应该是支持不同绑定的大部分工作。

In some of the projects I've been involved in, there's a mix of communications technologies where one choice would've been far easier to maintain-- this leads me to embrace the WCF decision for its inherent flexibility (WCF also supports MSMQ should the need arise to have queued communication). 在我参与的一些项目中,有多种通信技术混合在一起,其中一种选择本来就容易维护得多,这使我对WCF的决定具有固有的灵活性(WCF还支持MSMQ,如果需要排队等候通信)。

If you're concerned about the learning curve and you're sure that no future need will arise for you to embrace other communication topologies, remoting could be a useful solution. 如果您担心学习曲线,并且确定将来不再需要其他的通信拓扑,那么远程处理可能是一个有用的解决方案。 Remoting is probably the easiest, least-developer-work needed way of setting up IPC. 远程处理可能是设置IPC所需的最简单,最不需要开发人员的工作。

You should stay away from things like Web Services -- there's unnecessary overhead in the web service operations that WCF doesn't suffer from (WCF can still allow binary transport, for instance). 您应该远离诸如Web服务之类的东西-WCF不会遭受Web服务操作中不必要的开销(例如,WCF仍然可以允许二进制传输)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何建立两个不同EXE之间的通信 - How to establish the communication between the two Different EXEs 如何在C#中的两个程序之间发送数据? - How can I send data between two programs in C#? 我如何测量 c# 中两个关键事件之间的时间?(不是 windows.forms) - How can i measure the time between two key events in c# ?(not windows.forms) 2 个 Windows 窗体应用程序之间的通信 - Communication between 2 Windows Forms applications 我无法在两种表单之间传递数据 - I can't pass data between two forms 如何在Jupyter Notebook和Windows窗体应用程序之间传输数据? - How can I transfer data between a Jupyter Notebook and a windows forms application? 如何在两种形式之间来回移动而又不丢失输入的数据 - How can I move back and forth between two forms without loosing entered data 如何为两个 Windows Forms 应用程序共享一个隔离存储? - How to share one IsolatedStorage for two Windows Forms Applications? 如何在Windows窗体应用程序和WebBrowser控件之间进行通信 - How can I communicate between a windows forms application and a WebBrowser control 如何以安全的方式在不同服务器上的两个Web应用程序之间发送数据? - How to send data in secure way between two web applications on different servers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM