代码之家  ›  专栏  ›  技术社区  ›  Ali Tor

为什么在发送native消息时,“原生应用程序”直到Chrome关闭才会显示?

  •  0
  • Ali Tor  · 技术社区  · 5 年前

    我有一个扩展程序,可以在Chrome中发送消息。当我发送消息时,在chrome关闭之前,原生应用程序不会显示。这里有什么问题?

    chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
    
    valpairs = item.finalUrl + "e7dfa9a6-f9d8-4146-89f5-ca441f0f5b23" + valpairs;
    
    var port = chrome.runtime.connectNative('com.alto.downloadmanager');
    port.onMessage.addListener(function(msg) {
      console.log("Received" + msg);
    });
    port.onDisconnect.addListener(function() {
      console.log("Disconnected");
    });
    port.postMessage({ text: valpairs });
    
    
    chrome.downloads.cancel(item.id);
    });
    

    程序cs:

    static void Main(string[] args)
            {
                JObject data;
                var processed = "";
                while ((data = Read()) != null)
                {
                    processed = ProcessMessage(data);
                    Write(processed);
                    if (processed == "exit")
                    {
                        break;
                    }
                }
    
    
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1(processed));
    
            }
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Asesh Benjamin Lindley    5 年前

    您必须刷新该数据才能立即将其发送到您的本地消息传递主机。从你的帖子中还不清楚,你用什么API编写标准输入。如果您正在使用 FileStream 然后使用 FileStream.Flush 或者如果您正在使用 StreamWriter 然后使用 StreamWriter.Flush std::flush 在里面 C++ 正如我在这里提到的 thread