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

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

问题描述

我们已经单个机器上运行的两个应用程序,其中一个是网络应用程序,响应由读取XML文档(多个)。我们希望添加的情况下的每个请求所创建的或现有的文件取代了新的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.

由于Web应用程序适用于请求/响应周期,我们认为这个周期不应该干涉知道文件发生变化,请求时间在现场运行的系统,模糊之间的时间,我们必须拆分文件读取process.For目的我们使用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?

推荐答案

看起来像你会有兴趣的命名管道,使工控机,检查出的为例此链接,或的这个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页面最简单的说明了code(见在<一个href=\"http://msdn.microsoft.com/en-us/library/system.io.pipes.namedpipeclientstream.aspx\">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天全站免登陆