mobile - Dart - 生成多个隔离时在控制台中获取 'Malformed message'

标签 mobile dart flutter dart-isolates

我是 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/

相关文章:

c++ - 如何创建一个字符串数组来拆分一个字符,这些字符的单词由 ""分隔? C++

javascript - DOM 窗口尺寸何时确定?

dart - 是否可以在图标或 FontAwesomeIcons 等中选择随机图标

validation - 表单验证错误消息未完全显示-Flutter

ruby-on-rails - Rails 3.2 和 phonegap

ruby-on-rails - 设计移动mime类型,401仅显示flash消息

mongodb - 如何使用 dart 在 mongo 上创建一个简单的外观?

database - 如何解决 flutter sqlite 语法错误?

flutter - 错误: Couldn't resolve the package 'gql_code_builder' from repository layer

oop - 如何在dart/flutter中将变量内容传递给参数值?