簡體   English   中英

兩個不同應用程序之間的通信

[英]Communication between two different applications

我們在一台機器上運行了兩個應用程序,其中一個是通過讀取 xml 文檔來響應每個請求的 web 應用程序。我們希望添加這樣一種情況,即當創建新的 xml 文件或替換現有文件時,應用程序不能讀取文件,直到其全部更改為止,並​​且在發生這種情況時,它必須以舊文件進行響應。

由於 Web 應用程序適用於請求/響應周期,我們決定不應干擾這個周期,因為在實時運行的系統中文件更改和請求時間之間的時間是模糊的,我們必須拆分文件讀取過程。為此,我們使用FileSystemWatcher 在帶有 Windows 或控制台應用程序的本地機器上(或其他一些人說改用 WCF)。

現在我們在上述案例中提出問題,說我們如何通信這兩個(或更多)應用程序?

看起來您對啟用 IPC 的命名管道感興趣,請查看此鏈接以獲取示例,或查看此 MSDN 鏈接

MSDNNamedPipeServerStream 頁面抓取代碼說明最簡單(請參閱客戶端的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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM