您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

C# 实时动态刷新列表[如 DataGridView,ListView等

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   ThreadPool.QueueUserWorkItem(_ =>

  {

  this.Invoke((MethodInvoker)(() =>

  {

  try

  {

  lock (m_objLock5)

  {

  if (EVIs.Count != Evss.Count) return; //出现异常,返回不提取

  foreach (EntityVehicleInfo evi in EVIs)

  {

  int mcuid = evi.MCUID;

  /////////////////////////添加地理位置信息

  EntityVehicleInfo vehicleInfo = null;

  vehicleInfo = DataReader.Instance.HtVehicleInfo[mcuid]asEntityVehicleInfo;

  if (vehicleInfo == null) return;

  int Add_InfoIndex = dgvVehicleInfo.Rows.Add(1);

  DataGridViewRow row = dgvVehicleInfo.Rows[Add_InfoIndex];

  dituHelper.GetAddressByGPS(vehicleInfo.Longitude, vehicleInfo.Latitude, Add_InfoIndex);

  row.Cells["VehicleInfoMCUID"].Value = vehicleInfo.MCUID;

  row.Cells["VEHICLENO"].Value = vehicleInfo.VehicleNo;

  row.Cells["ONLINE"].Value = vehicleInfo.Online;

  row.Cells["ACC"].Value = vehicleInfo.ACC;

  //row.Cells["LONGITUDE"].Value = vehicleInfo.Longitude.ToString("f5");

  //row.Cells["LATITUDE"].Value = vehicleInfo.Latitude.ToString("f5");

  row.Cells["ANGLE"].Value =UtilityHelper.Angle2Direction((int)vehicleInfo.Angle);

  row.Cells["VELOCITY"].Value = vehicleInfo.Velocity;

  row.Cells["LOCATIONSTATE"].Value = vehicleInfo.LocationState;

  row.Cells["RECEIVETIME"].Value = vehicleInfo.ReceiveTime;

  ////////////////////////////添加状态信息

  EntityVehicleState vehicleState = null;

  vehicleState = DataReader.Instance.HtVehicleState[mcuid]asEntityVehicleState;

  if (vehicleState == null) return;

  int Add_StateIndex = dgvVehicleState.Rows.Add(1);

  DataGridViewRow row2 = dgvVehicleState.Rows[Add_StateIndex];

  row2.Cells["VEHICLENOS"].Value = vehicleInfo.VehicleNo.ToString();

  vehicleInfo = null;

  row2.Cells["PositionTime"].Value = vehicleState.PositionTime.ToString();

  row2.Cells["STOPFUEL"].Value = vehicleState.StopFuel ?"是" : "否";

  row2.Cells["FUELCUT"].Value = vehicleState.FuelCut ? "断油电" : "通油电";

  row2.Cells["AUTODEFENCE"].Value = vehicleState.AutoFence ?"设防" : "解防";

  row2.Cells["TRUNKBOOT"].Value = vehicleState.TrunkBoot ?"开启" : "关闭";

  row2.Cells["BRAKING"].Value = vehicleState.Braking ? "刹车踩下" : "刹车松开";

  row2.Cells["DOOROPEN"].Value = vehicleState.DoorOpen ? "打开" : "关闭";

  row2.Cells["ACCON"].Value = vehicleState.ACCOn ? "点火" :"熄火";

  row2.Cells["POWERSAVER"].Value = vehicleState.PowerSaver ?"是" : "否";

  vehicleState = null;

  }

  }

  }

  catch (Exception ex)

  {

  LogHelper.Writeln("Instance_NotifyInfo " + ex.StackTrace);

  }

  }));

  });

  效果如下:

C# 实时动态刷新列表[如 DataGridView,ListView等 三联