Use threads to generate static pages

Source: Internet
Author: User

Public class work
{
Public int state = 0; // 0-not started, 1-running, 2-successful, 3-failed
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) // ensure that the critical section is occupied by a 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 ()
{< br> // 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 ();
}

}

 

// Above Code Perform a time-consuming database operation
State = 2;
//}
// Catch
//{
// Errortime = datetime. now;
// State = 3;
//}
// Finally
//{
// Finishtime = datetime. now;
//}
}
}

}
 

How can I change the CPU usage to 35%-50%.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.