Here is an introduction to multithreading and thread pool.
Http://edobnet.cnblogs.com/archive/2005/11/29/287094.html
// Private int threadnum = 0;
// Private autoresetevent myresetevent = new autoresetevent (false );
/**/ /// <Summary>
///Thread Recorder
/// </Summary>
Private Int Number = 0 ;
/**/ /// <Summary>
///Thread pool execution
/// </Summary>
Public Void Execute ()
{
Int Maxcount = Int . Parse (configurationsettings. receivettings [ " Count " ]);
Int Time = Int . Parse (configurationsettings. receivettings [ " Time " ]);
Foreach (Tg_evalutebasedatasset Service In This )
{
// System. Threading. threadstart Ts = new system. Threading. threadstart (service. getxmlresult );
// System. Threading. Thread th = new system. Threading. Thread (TS );
// Th. Start ();
Waitcallback async = New Waitcallback (fexeute );
While ( True )
{
Monitor. Enter (number );
If (Number > Maxcount)
Thread. Sleep (time );
Else
Break ;
Monitor. Exit (number );
}
If (Threadpool. queueuserworkitem (async, Service ))
Interlocked. increment ( Ref Number );
}
While ( True )
{
// Myresetevent. Set ();
Monitor. Enter (number );
If (Number <= 0 )
Break ;
Else
Thread. Sleep (time );
Monitor. Exit (number );
}
Ontgfinishreport ( New Eventargs ());
}
/**/ /// <Summary>
/// The thread executes a computing task.
/// </Summary>
/// <Param name = "Param"> Execution object <See CREF = "glenet. HG. htresolver. tg_evalutebasedatasset"> Tg_evalutebasedatasset </See> </param>
Public Void Fexeute ( Object Param)
{
// Myresetevent. waitone ();
Using (Tg_evalutebasedatasset Service = (Tg_evalutebasedatasset) PARAM)
{< br> service. doresult ();
writefile (path, service);
ontgreport ( New reportevent (service. te_pass_range, service. te_year, service. te_month, int . parse (service. te_ I _e_flag), int . parse (service. te_entry_type), number);
}
Interlocked. decrement ( Ref Number );
Console. writeline ( " Left: " + Number );
}
ByProgramControls the number of threads and is protected by monitor!