c# - 并行处理列表中可用的项目使用 Parallel.ForEach
问题描述
我正在尝试为我的项目开发网络监视器。我正在使用 Parallel.ForEach 将 ping 并行发送到 List IPListAll 中列出的所有 IP Addressess。
我想处理从所有 PC 收到的回复,但是我的代码永远不会到达 MessageBox.Show 和 DisplayChangeOnReply 函数。我被困在这里。请帮忙,我不知道我做错了什么。我的代码附在下面以供参考。
while(true)
{
object pinglock = new object();
Parallel.ForEach(IPListAll,ipaddr =>
{
lock(pinglock)
{
reply = Ping.Send(ipaddr,500); // this line is being executed always
MessageBox.Show(ipaddr); // Execution not reaching here
}
DisplayChangeOnReply(reply,ipaddr); // Execution nor reaching here
});
}
解决方案
推荐阅读
- prometheus - 图计数 Prometheus PushGateway API 调用
- javascript - 第一个 NodeJS 应用程序 - 如何解决 MODULE NOT FOUND 和其他问题?
- c# - 填充项目列表时C#无法更新组合框
- gitlab - 如果用户几天不登录,是否可以禁用 Gitlab 锁定 LDAP 帐户?
- sql - 如何将 JOIN 表中的 ID 迁移到 PostgreSQL 中的外键列
- c++ - 当没有异常时,我应该为每个函数添加 noexcept 吗?
- node.js - 启动不和谐机器人时出现此错误
- php - gcloud PHP没有连接到sql
- python - Python selenium无法通过xpath找到whatsapp web textarea
- python - Python数据框检测语言并翻译