I have the following code in c # with windows forms inside a button:
new Task(() => {
Task[] tareas = {
Task.Factory.StartNew(() => metodo1(), CancellationToken.None, TaskCreationOptions.AttachedToParent, tarea),
Task.Factory.StartNew(() => metodo2(), CancellationToken.None, TaskCreationOptions.AttachedToParent, tarea)
};
}).Start();
public void metodo1() {
for (int v = 0; v < arreglointernet.Length; v++) {
if (progressBar1.Visible == false) {
progressBar1.Visible = true;
}
if (progressBar1.Value < 100) {
progressBar1.Value++;
}
if (arreglointernet[v].Contains("D")) {
richTextBox3.Text += arreglointernet[v].ToString() + "\nindex of " + arreglointernet[v].LastIndexOf(";") + "\n" + "Debito de internet aplicado\n";
} else {
richTextBox3.Text += arreglointernet[v].ToString() + "\nindex of " + arreglointernet[v].LastIndexOf(";") + "\n" + "credito de internet aplicado\n";
}
}
}
public void metodo2() {
for (int vv = 0; vv < arregloproceso.Length; vv++) {
if (progressBar1.Visible == false) {
progressBar1.Visible = true;
}
if (progressBar1.Value < 100) {
progressBar1.Value++;
}
if (arregloproceso[vv].Contains("D")) {
richTextBox3.Text += arregloproceso[vv].ToString() + "\nindex of " + arregloproceso[vv].LastIndexOf(";") + "\n" + "Debito de proces aplicado\n";
} else {
richTextBox3.Text += arregloproceso[vv].ToString() + "\nindex of " + arregloproceso[vv].LastIndexOf(";") + "\n" + "credito de proces aplicado\n";
}
}
}
The above generates the following result after method 1 or method 2:
Arrangements with transactions are ready to begin with the processI; C; 2000 index of 3 Internet credit applied I; D; 1000 index of 3 Debit of internet applied
index of -1 Internet credit applied P; C; 4000.54 index of 3 applied process credit P; D; 2000 index of 3 Debit of applied process
index of -1 applied process credit
index of -1 applied process credit
How do I not take into account those indexOf -1 is to say that the thread stops when there is no data in an array ?????