采用线程生成静态页面

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% 改怎么解决。
posted @ 2009-01-16 11:26  王继坤  阅读(191)  评论(0编辑  收藏  举报
我要啦免费统计