两个不同应用程序之间的通信 [英] Communication between two different applications

查看:53
本文介绍了两个不同应用程序之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have two applications running on single machine,one of which is web application that responses every request by reading xml document(s).We wish to add the case that when the new xml file is created or existing file has replaced,application must not read file until its all changed and by the time the case happens,it must respond with old file.

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

Since web applications works for request/respond cycle,we decided that this cycle shouldn't be interfered knowing that time between file changing and request time is obscured in live-running system,we must split file reading process.For that purpose,we use FileSystemWatcher in local machine with windows or console application(or some other says use WCF instead).

既然我们在上述案例中提出问题,那么我们如何沟通这两个(或更多)应用程序?

Now that we come to question in above case,saying how can we communicate these two (or more) applications?

推荐答案

看起来您对启用 IPC 的命名管道感兴趣,请查看 此链接 示例,或这个 MSDN 链接.

Look like you'd be interested in Named Pipes to enable IPC, check out this link for an example, or this MSDN link.

MSDN 的 NamedPipeServerStream 页面 中获取代码最简单的说明(请参阅 NamedPipeClientStream 页面 用于客户端):

Grabbing the code from the NamedPipeServerStream page of MSDN illustrates most simply (see the NamedPipeClientStream page for the client side):

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);
    }
}

这篇关于两个不同应用程序之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆