两个不同应用程序之间的通

我们在单机上运行两个应用程序,其中一个是通过读取xml文档来响应每个请求的web应用程序。我们希望添加一个情况,即当新的xml文件被创build或现有的文件被replace时,应用程序不能读取文件直到其全部更改,并且在发生这种情况时,它必须用旧文件进行响应。

由于Web应用程序在请求/响应周期中工作,我们认为这个周期不应受到干扰,因为在实时运行的系统中,文件更改和请求时间之间的时间被遮蔽了,所以我们必须拆分文件读取过程。为此,我们使用FileSystemWatcher在本地机器与Windows或控制台应用程序(或其他一些说,使用WCF代替)。

现在我们在上面的例子中提出质疑,说我们应该如何沟通这两个(或更多)应用程序?

看起来你有兴趣在命名管道启用IPC,检查这个链接的例子,或这个MSDN链接 。

从MSDN的NamedPipeserverStream页面抓取代码最简单(请参阅客户端的NamedPipeClientStream页面 ):

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