Posted on: 9/4/2013 3:25:22 AM | Views : 642

Hi, all
In my project, I want to use multi threads to generating a report(this function has been packaged one .dll, and it control db connection, write data into excel, crystal report, zip folder,etc. ).
this fucntion will use lots of CPU, so too many threading is not well.
in the code, i define one variable to record threading num.
int _ThreadingNum = 0; In main code:
Foreach(Datarow row in table.Rows) { While(_ThreadingNum >= 3) { Thread.Sleep(TimeSpan.FormMinutes(1)); } Thread t = new Thrad(_ProcessReport); _ThreadingNum += 1; t.Start(_prams); } The value of _ThreadingNum will -1 when _ProcessReport() is finished.
 If table's row count is few, it can works, but many records, it will cause ContextSwitchDeadlock.
Is any recommendation?
...

Go to the complete details ...