我是 dart 新手,我正在尝试使用隔离来运行多个算法以更有效地多次运行它们,但是,当使用 Isolate.spawn 调用多个函数时,我开始在控制台中收到“格式错误的消息”,它仍然有效,但我想知道为什么我会收到此消息,也欢迎任何改进代码的帮助,因为我仍在学习使用隔离的复杂性
stressTest()
{
ReceivePort rpDouble = new ReceivePort();
ReceivePort rpString = new ReceivePort();
ReceivePort rpInteger = new ReceivePort();
int counter = 0;
int tempoTotal = 0;
rpDouble.listen((data) {
counter++;
tempoTotal += data; //data is a stopwatch.toMilliseconds
setState(() { //updating the "progress" and the time it took to run the algorithm in the ui
test = counter.toString() + '%';
_counter = tempoTotal.toString();
});
});
rpInteger.listen((data){
counter++;
tempoTotal += data;
setState(() {
test = counter.toString() + '%';
_counter = tempoTotal.toString();
});
});
rpString.listen((data){
counter++;
tempoTotal += data;
setState(() {
test = counter.toString() + '%';
_counter = tempoTotal.toString();
});
});
for(int i = 0; i < 5; i++) {
Isolate.spawn(DoubleTest, rpDouble.sendPort);
Isolate.spawn(StringStress, rpString.sendPort);
Isolate.spawn(integerTest, rpInteger.sendPort);
}
}
}
DoubleTest、StringStress 和 IntegerTest 是将一个 stopwatch.toMilliseconds 整数返回给 sendPort 的函数。
提前致谢,任何帮助表示赞赏
最佳答案
当您想查看性能应用程序时会发生这种情况。但是,在重新加载应用程序期间,重新同步数据会导致抖动性能无法获取地址或中断导致该消息的进度阅读器。这不会影响应用程序或您的应用程序错误。如果您需要阅读“内存使用情况”或“帧渲染时间”,则只需重新启动 IDE 并重新启动即可。
关于mobile - Dart - 生成多个隔离时在控制台中获取 'Malformed message',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53383779/