zoukankan      html  css  js  c++  java
  • Task加载数据

    //父级

    string F_Sql = "select id,code,name from ftable where deleted=0 order by convert(int,code)";

    DataTable F_dt = SqlHlper.ExecuteDt(F_Sql);
    string J_AcInfo = "[";

    //父级数据条数
    int count = F_dt.Rows.Count;

    //分进程 5条一进程
    int rowcount = 0;
    if ((count % 5) > 0)
    {
    rowcount = (count / 5) + 1;
    }
    Task[] task = new Task[rowcount];
    //存放检测的结果
    Dictionary<string, string> GetIPZT = new Dictionary<string, string>();
    for (int k = 0; k < rowcount; k++)
    {
    List<DataRow> dt_row = F_dt.AsEnumerable().ToList().Skip(k * 5).Take(5).ToList();
    task[k] = Task.Factory.StartNew(()=>{
    foreach (var item in dt_row)
    {
    string AcInfo = "{";
    AcInfo += ""f_no":"" + item["code"].ToString() + "",";
    AcInfo += ""f_name":"" + item["name"].ToString() + "",";
    AcInfo += ""ac_data":[ ";

    //查询子数据

    string Ac_Sql = "select * from c";

    DataTable Ac_dt = SqlHlper.ExecuteDt(Ac_Sql);
    for (int j = 0; j < Ac_dt.Rows.Count; j++)
    {
    //获取状态
    string zt = "失败";
    string key = Ac_dt.Rows[j]["a"].ToString() + "-" + Ac_dt.Rows[j]["b"].ToString();
    //判断是否有检测过,有则不继续检测直接获取值,无则需检测
    if (!GetIPZT.ContainsKey(key))
    {
    //根据键查询对应的值
    zt = GetIPZT[key];
    }

    AcInfo += "{"sn":"" + Ac_dt.Rows[j]["sn"].ToString() + "","ip":"" + Ac_dt.Rows[j]["ip"].ToString() + "","wh":"" + Ac_dt.Rows[j]["wh"].ToString() + ""},";
    }
    J_AcInfo += AcInfo.Substring(0, AcInfo.Length - 1) + "]},";
    }

    });
    }

    //等待所有进程执行完成
    Task.WaitAll(task);
    J_AcInfo = J_AcInfo.Substring(0, J_AcInfo.Length - 1) + "]";
    return J_AcInfo;

  • 相关阅读:
    javamail发送邮件
    java复制文件夹中的所有文件和文件夹到另一个文件夹中
    jsp中使用out和response.getOutputStream的方法
    PHP数组用法
    PHP中的session
    java中list按照某个属性排序方法
    java读取xml文件内容
    C#实现验证码
    java实现验证码功能
    Java IO(四)------字节输入输出流
  • 原文地址:https://www.cnblogs.com/luckys/p/11711638.html
Copyright © 2011-2022 走看看