Hy all,
I'm developing a windowsforms app and I'm trying to use threads.
public void Thread1(DataTable dt2,DataTable dt,int x,int y)
{
string cui = "";
string cod_asis = "";
for (int i = x; i < y; i++)//dt.Rows.Count
{
var currentRow = dt.Rows[i];
cui = currentRow["cui"].ToString().Trim();
cod_asis = currentRow["cod_asis"].ToString().Trim();
cui = Main_App.Clase.VerificareCIF.FormatezCIF(cui);
Verificare_Online_single(cui, cod_asis, dt2.Rows[i], dt.Rows[i],script1); //this method is takes some time and with this I write the datatable
//Thread.Sleep(1);
}
}
private void Parcurgere_Verificare_Online()
{
DataTable dt = (DataTable)gridControl.DataSource;
DataTable dt2 = CreateTable(dt.Rows.Count);//tbl;
foreach (System.Data.DataColumn col in dt.Columns) col.ReadOnly = false;
foreach (System.Data.DataColumn col in dt2.Columns) col.ReadOnly = false;
DevExpress.Data.CurrencyDataController.DisableThreadingProblemsDetection = true;
ThreadStart job = new ThreadStart(() => Thread1(dt2, dt, 0, dt.Rows.Count/2));
Thread thread = new Thread(job);
// thread.Priority = ThreadPriority.Highest;
//thread.IsBackground = true;
thread.Start();
ThreadStart job2 = new ThreadStart(() => Thread1(dt2, dt, dt.Rows.Count /2, dt.Rows.Count));
Thread thread2 = new Thread(job2);
//thread2.IsBackground = true;
thread2.Start();
thread.Join();
thread2.Join();
gridControl.DataSource = null;
gridControl.DataSource = dt2;
}
Is there a better way to do it because I don't know another way and I am new at using threads?