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% 改怎么解决。
     
    ------------------------------------------------------------------------------------
    作者:王继坤

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    ------------------------------------------------------------------------------------
  • 相关阅读:
    MyEclipse配置输出控制台信息至文本文件里
    IOS开发证书显示“此证书的签发者无效”解决方法
    leetcode之Find All Numbers Disappeared in an Array
    自己定义控件三部曲视图篇(二)——FlowLayout自适应容器实现
    浅谈BloomFilter【上】基本概念和实现原理
    mybatis 常用的jabcType与javaType对应
    springboot WebMvcConfigurerAdapter替代
    动态insert mybatis与ibatis
    动态set mybatis与ibatis的写法
    springboot 配置mybatis打印sql
  • 原文地址:https://www.cnblogs.com/wangjikun3/p/1376877.html
Copyright © 2011-2022 走看看