c# 多线程的使用

发布时间 2023-09-20 17:44:25作者: 比特币忠实玩家

需求描述  需要定期获取设备的状态 目前需要ping的设备只有 200个左右 

 

 耗时 177.429 秒

 

 

 

            Stopwatch sw = new Stopwatch();
            sw.Start();
            try
            {
         
                var list= _assetinfoService.GetLists(ip:"true"); 

                for (int i = 0; i < list.Count; i++)
                {
                    var isTrue = CommonHelper.PingIp(list[i].IP4);

                    list[i].QYZT= isTrue ? "1" : "2";                                                    
                }

                _assetinfoService.BathUpdate(list);
            }
            catch (Exception ex)
            {

                return Fail("失败,", ex.Message);
            }
            sw.Stop();  
            return Success(@"成功{sw.ElapsedMilliseconds}ms"+ sw.ElapsedMilliseconds);