Problem:
I am currently calling 3 functions inside my code that execute behind each other, which will take some time to finish. So I was wondering if there is a way to call them at the same time, for example using a loop Parallel.For
.
If I could use a loop Parallel.For
, how can I succeed? Will it be right?
Parallel.For(0, 1, i =>
{
bool check1 = function1(address);
bool check2 = function2(address);
bool check3 = function3(address);
});
My current code is:
private void check()
{
for (int i = 0; i < dataGridView1.RowCount; i++)
{
string address = dataGridView1.Rows[i].Cells[0].Value.ToString();
try
{
if (address.Length < 6)
{
bool check1 = function1(address);
bool check2 = function2(address);
bool check3 = function3(address);
}
else
{
dataGridView1.Rows[i].Cells[2].Value = "Error";
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
source
share