为什么没有本地应用程序会在发送本地消息时直到Chrome关闭后才显示?

问题描述 投票:0回答:1

我有一个扩展程序,可以在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);
});

Program.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));

        }
c# google-chrome-extension chrome-native-messaging
1个回答
0
投票

您必须刷新该数据才能立即将其发送到您的本机消息传递主机。从您的帖子中还不清楚您正在使用哪种API写入标准输入。如果您使用的是FileStream,请使用FileStream.Flush;如果您使用的是StreamWriter,请使用StreamWriter.Flush中的std::flushC++,正如我在thread]中提到的那样>

© www.soinside.com 2019 - 2024. All rights reserved.