c# - 为什么在发送 nativemessage 时 Chrome 关闭之前,本机应用程序不显示?
问题描述
我有一个在 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));
}
解决方案
您必须刷新该数据才能立即将其发送到您的本地消息传递主机。从您的帖子中不清楚,您使用什么 API 来写入标准输入。如果您正在使用,FileStream
则使用FileStream.Flush,或者如果您正在使用,StreamWriter
则使用StreamWriter.Flush和C++,正如我在此线程中提到std::flush
的那样
推荐阅读
- javascript - 如何使用切换类列表更改 HTML 表中行的背景
- java - 如何在主方法中调用另一个方法?
- c++ - 为什么既不使用复制构造也不使用移动构造?
- javascript - 使用 Document.write() 和一个对象来创建
在 HTML 中
- c# - OnCollisionEnter2D 只被调用一次
- rest - Fuel HTTP - 避免 URL 编码
- entity-framework - 我有“蟑螂汽车旅馆数据”——数据进入数据库正常,无法退出
- mysql - 使用保存在数据库中的数组连接表以用于匹配表
- php - 如何按日期键对数组进行排序?
- vb.net - How to implement multiple catches with error provider if textbox is empty