zoukankan      html  css  js  c++  java
  • 采用线程生成静态页面

    public class work
    {
        public int State = 0;//0-没有开始,1-正在运行,2-成功结束,3-失败结束
        public DateTime StartTime;
        public DateTime FinishTime;
        public DateTime ErrorTime;
        public string drop { get; set; }
        public string area { get; set; }
        public string ml = "";
        public Boolean ck;
        public void runwork()
        {
            lock (this)//确保临界区被一个Thread所占用
            {
                if (State != 1)
                {
                    State = 1;
                    StartTime = DateTime.Now;
                    System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(dowork));
                    thread.Start();
                }
            }
        }

        private void dowork()
        {


            using (var db = new fei())
            {
             //   try
             //{
                    var h1 = from d in db.Class
                             where d.Class_Code.IndexOf("0012") == 0 && d.Class_Code.Length == 12
                             select d;
                    foreach (var h2 in h1)
                    {


                        if (drop.Contains(h2.Class_Code))
                        {
                            //val += h2.Class_Code+ "|";
                            html aa = new html();
                            aa.code = h2.Class_Code;
                            aa.area = area;
                            aa.ml = ml;
                            aa.ck = ck;
                            aa.to_html();
                        }

                    }


                    //以上代码执行一个比较消耗时间的数据库操作
                    State = 2;
       //        }
       //         catch
       //        {
       //            ErrorTime = DateTime.Now;
       //          State = 3;
       //       }
       //      finally
       //       {
       //           FinishTime = DateTime.Now;
       //}
            }
        }

        }
     

    占用cpu 到 35%-50% 改怎么解决。
     
    ------------------------------------------------------------------------------------
    作者:王继坤

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    ------------------------------------------------------------------------------------
  • 相关阅读:
    高度百分比生效的方法height:100%
    您可以尝试改变浏览器大小,这个元素依然是水平垂直居中的哦!
    百分比
    百分比布局
    mysql 用户管理
    lnmp安装--linux通过tar.gz源码包安装mysql
    linux内核编译,内核参数修改
    CentOS安装mplayer
    x86与x64与x86_64
    centos 关闭触摸板,触摸板点击
  • 原文地址:https://www.cnblogs.com/wangjikun3/p/1376877.html
Copyright © 2011-2022 走看看