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%.