Doubts regarding the use of threads and parallel tasks.

  • Thread starter Thread starter rta_vix
  • Start date Start date
R

rta_vix

Guest
Friends, I have the following problem, I have a spreadsheet that consists of a single judicial number for 2 people, but this spreadsheet has too many court cases related to other people, not having another relationship of these authors with a single process. But when I import these worksheets into my database, if I have two people related to the same process, it ends up generating a code of the same process for these two people, and the idea was to generate only 1 code, I suspect that my Problem is not the database, but in my code, because I'm reading the first 100 lines, and Breaking into 10 threads, I believe my problem is in that part, because my spreadsheets come with 670 to 980, and a process can come for these two people, but when importing this generating the process code for these two people, and this can not. I believe that by dividing the lines and playing in 10 threads, this happens. Can you guide me through kindness?


protected void import_Click (object sender, EventArgs and)
{

DataTable Data = new DataTable ();

var recordsValid = ((DataTable) Data) .Rows.OfType <DataRow> (). Skip (5);
// Delete the last line
recordsValid = RecordsValid.Take (RecordsValid.Count () - 1);
// read 100 out of 100 records
int amount_for_page = 100;
int total_de_pages;
// Count valid records
int qtd_total_registers = recordsValid.Count ();
// Perform mathematical calculations for total pages.
total_de_pages = (int) Math.Ceiling ((double) qtd_total_registers / amount_by_page);


if (!fileInvalidated)
{
thisValidaDuplicidadeInteressado ();
// Creating Parallel Tasks
List <System.Threading.Tasks.Task> TasksParallel = new List <System.Threading.Tasks.Task> ();
// Creating a new list and sorting by descending name

for (int j = 0; j <total_of_pages; j ++)
{

var page = j;
// read the 100 lines
var linesPorPage = recordsResults.Skip (page * quantity_by_page) .Take (quantity_by_page);

// Breaking into 10 threads, I will break the list with the extension created below
var data_rows_divided = linesPorPagina.SplitList(10);

foreach (var linesDivided in data_rows_divided)
{
// var value = SplitData.Field <int> (1);
// I ADD TO MY PARALLEL TASK LIST
TasksParalelas.Add (TableTransform (split lines, j, userLog));

}

}



// START THE PARALLEL TASKS
foreach (var task in TasksParallel)

task.Start ();

// NOW I EXPECT ALL JOBS TO COMPLETE
System.Threading.Tasks.Task.WaitAll (TasksParalelas.ToArray ());

// ClientScript.RegisterStartupScript (Page.GetType (), "Loading ...", "<script> document.getElementById ('progress'). Style.width = '60%'; </ script>");
}

else
{
logimport.Visible = true;
loglbl.Text = log.ToString ();
ClientScript.RegisterStartupScript (typeof (string), "Error", "<script> alert ('File not imported check the error log on the screen.') </ Script>");
}
}
}



My thread method:

private System.Threading.Tasks.Task Processing table (IEnumerable <DataRow> dataparam, int i, UserLibrary user)
{

Action <object> processing = (data) =>
{
GC.Collect ();
/ * if (NHibernate.Context.ThreadStaticSessionContext.HasBind (NhibernateHelper.SessionFactory.)) * /
NHibernate.Context.ThreadStaticSessionContext.Bind (NhibernateHelper.HelpThreading (). OpenSession ());


ISession session = ThreadStaticSessionContext.Unbind (NhibernateHelper.HelpThreading ());
if (session! = null)
{
if (session.Transaction! = null && session.Transaction.IsActive)
{
session.Transaction.Rollback ();
}
else
{
sessao.Flush ();
}
session.Close ();

}
// Tasks based asynchronously
System.Threading.Tasks.Task task_execute = new System.Threading.Tasks.Task (processing, dataparam);

return task_address;
}
}

Continue reading...
 
Back
Top