c# - Speeding up Parallel.ForEach iterating through datatable and rendering crystal report as byte stream -


good day,

i attempting speed processing of 5000 rows received database, render crystal report, export byte stream , save byte stream in database table. using parallel.foreach on datatable. uses 40 parallel processes sequentially iterates 125 (i.e 5000/40) records of 5000 rows. take approximately 5 minutes 5000 @ moment. please assist on suggestions on how speed up.

datatable dtbills = new datatable("dtbills");//i used odbcdataadapter fill 5000 records  private void parallelprocess()         {             int numbills = 5000;             int numprocesses = 40;             int numsequential = numbills / numprocesses;              int p=0;              if (numbills < numprocesses)                 p = numbills;             else                 p = numprocesses;              parallel.for(1, p+1, new paralleloptions { maxdegreeofparallelism = 40 }, =>             {                 sequentialprocess(numsequential,i);              });          }          private void sequentialprocess(int batch,int num)         {             reportdocument cryrpt = new reportdocument();             cryrpt.load(application.startuppath + "\\" + "bill.rpt");              foreach(datarow drow in dtbills.rows.cast<system.data.datarow>().skip((num - 1) * batch).take(batch).copytodatatable().rows)              {                  cryrpt.setparametervalue(..... //here set crystal report parameter values                  stream stream = cryrpt.exporttostream(crystaldecisions.shared.exportformattype.portabledocformat);                 byte[] contents = new byte[stream.length];                 stream.read(contents, 0, (int)stream.length);                 stream.close();                  if (!string.isnullorempty(sconnstr))                 {                     using (sqlconnection sconn = new sqlconnection(sconnstr))                     {                          string qry = @"insert ....."                         using (sqlcommand cmd = new sqlcommand(qry, sconn))                         {                              cmd.commandtype = commandtype.text;                              cmd.parameters.addwithvalue(// set values insert here 1 of contents                              cmd.connection = sconn;                              sconn.open();                             cmd.executenonquery();                             sconn.close();                          }                       }                 }              }              cryrpt.close();             cryrpt.dispose();          } 

any assistance appreciated


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -