Myr*_*yra 5 c# windows asp.net wcf
我们在一台机器上运行了两个应用程序,其中一个是通过读取xml文档来响应每个请求的Web应用程序.我们希望添加一个案例,即在创建新的xml文件或替换现有文件时,应用程序不能读取文件直到全部更改,并且在案例发生时,它必须使用旧文件进行响应.
由于Web应用程序适用于请求/响应周期,我们认为不应该干扰这个周期,因为知道文件更改和请求时间之间的时间在实时运行系统中是模糊的,我们必须分割文件读取过程.为此,我们使用带有Windows或控制台应用程序的本地机器中的FileSystemWatcher(或其他一些人说使用WCF代替).
现在我们在上面的案例中提出质疑,说我们如何沟通这两个(或更多)应用程序?
Gra*_*mas 13
看起来您对命名管道感兴趣以启用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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26789 次 |
| 最近记录: |