gpt4 book ai didi

c# - 两个不同应用程序之间的通信

转载 作者:可可西里 更新时间:2023-11-01 13:28:26 25 4
gpt4 key购买 nike

我们有两个应用程序在一台机器上运行,其中一个是 Web 应用程序,它通过读取 xml 文档来响应每个请求。我们希望添加这样的情况,即当创建新的 xml 文件或替换现有文件时,应用程序在文件全部更改之前不得读取文件,并且在这种情况发生时,它必须使用旧文件进行响应。

由于 web 应用程序为请求/响应周期工作,我们决定不应该干扰这个周期,因为知道文件更改和请求时间之间的时间在实时运行的系统中是模糊的,我们必须拆分文件读取过程。为此目的,我们在带有 Windows 或控制台应用程序的本地计算机中使用 FileSystemWatcher(或者其他一些人说使用 WCF)。

既然我们在上述案例中提出疑问,我们如何才能与这两个(或更多)应用程序通信?

最佳答案

看起来您对启用 IPC 的命名管道感兴趣,请查看 this link例如,或 this MSDN link .

NamedPipeServerStream page of MSDN 中获取代码最简单的说明(请参阅客户端的 NamedPipeClientStream page):

using (NamedPipeServerStream pipeServer =
new NamedPipeServerStream("testpipe", PipeDirection.Out))
{
Console.WriteLine("NamedPipeServerStream object created.");

// Wait for a client to connect
Console.Write("Waiting for client connection...");
pipeServer.WaitForConnection();

Console.WriteLine("Client connected.");
try
{
// Read user input and send that to the client process.
using (StreamWriter sw = new StreamWriter(pipeServer))
{
sw.AutoFlush = true;
Console.Write("Enter text: ");
sw.WriteLine(Console.ReadLine());
}
}
// Catch the IOException that is raised if the pipe is broken
// or disconnected.
catch (IOException e)
{
Console.WriteLine("ERROR: {0}", e.Message);
}
}

关于c# - 两个不同应用程序之间的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5676847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com