[英]How can I send data between two programs in C#?
我有两个应用程序 - > App1和App2。 App1通过使用System.Diagnostic.Process()传递一些命令行参数来打开App2。 用户现在可以访问App2。
但是,当用户在App1中更改某些命令参数时,我需要打开现有的应用程序(App2)而不使用新参数关闭它。
我怎样才能做到这一点?
任何反馈都会有所帮助。
另一种选择可能是基于WCF的解决方案。 请参阅WCF聊天示例
你应该使用IPC。 有关一些有用的链接,请参阅C#中的IPC机制 - 用法和最佳实践 。
为什么不使用套接字(客户端和服务器)的普通旧TCP / IP。
我将使用WindowsFormsApplicationBase
类(来自Microsoft.VisualBasic
程序集)和Program.cs
文件中的以下代码:
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
namespace TestSolution
{
sealed class Program : WindowsFormsApplicationBase
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] commandLine)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var program = new Program()
{
IsSingleInstance = Properties.Settings.Default.IsSingleInstance
};
// Here you can perform whatever you want to perform in the second instance
// After Program.Run the control will be passed to the first instance
program.Run(commandLine);
}
protected override void OnCreateMainForm()
{
MainForm = new ImportForm();
}
protected override bool OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
{
// This code will run in the first instance
return base.OnStartupNextInstance(eventArgs);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.