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 xm开发者_运维百科l 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.
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?
Look like you'd be interested in Named Pipes to enable IPC, check out this link for an example, or this MSDN link.
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);
}
}
精彩评论