forse questo si avvicina di più a quello che credo voglia ottenere :
codice:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Collections;
namespace testHtmlIt
{
public delegate void Continua();
public partial class Form1 : Form
{
int c = 0;//creo un indice per l'array che sarà valorizzato nel ciclo successivo (sarebbe l'ID del DB)
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//dichiaro un nuovo thread e lo avvio per evitare di bloccare la form
Thread t = new Thread(startThread);
t.Start();
c = 0;//riposto sempre a 0 l'ID (per praticità)
}
void startThread()
{
ArrayList arrList = (ArrayList)class1.arr.Clone();//toricamente sto copiando i dati dal db per iterarli
foreach (string arr in arrList)// itero idati
{
if (arr == "c")//se trovo un anomalia entro nella condizione
{
Thread t = new Thread(startThread2);//creo e avvio un nuovo thread per permettere la modifica e mettere in attesa questo thread
t.Start();
while (!class1.Riparti) ; //adesso questo thread è in attesa della modifica da parte dell'altro form
///finche quest'ultimo non modifica la proprietà della classe che sto usando per simulare il db
class1.Riparti = false;//per eventali ripetizioni del tutto
}
c++;//incremento l'ID ad ogni ciclo
}
//a questo punto sono stati modificati tutti i valori contenenti "c" nel pseudoDB in maniera sequenziale
c = 0;
}
void startThread2()
{
if (this.InvokeRequired)//necessario per avviare il secondo form dall'altro thread
{
this.Invoke(new Continua(continua));
}
else continua();
}
void continua()//avvio il form secondario prendendo e passandoli l'ID da modificare
{
Form2 f2 = new Form2(c);
f2.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace testHtmlIt
{
public partial class Form2 : Form
{
int index;
public Form2()
{
InitializeComponent();
}
public Form2(int index)
{
InitializeComponent();
this.index = index;
this.textBox1.Text = class1.arr[index].ToString();// imposto il valore da mofdificare
}
private void button1_Click(object sender, EventArgs e)
{
class1.arr[index] = this.textBox1.Text;//effettuo la modifica (ricorda che stiamo simulando un DB
class1.Riparti = true;//imposto il valore per far ripartire il thread in attesa
this.Close();
}
}
public static class class1//solo per simulare il DB
{
static object lockArr;
static object lockBool;
static ArrayList arrList;
static bool riparti;
public static ArrayList arr
{
get
{
lock (lockArr)
{
return arrList;
}
}
set
{
lock (lockArr)
{
arrList = value;
}
}
}
public static bool Riparti
{
get
{
lock (lockBool)
{
return riparti;
}
}
set
{
lock (lockBool)
{
riparti = value;
}
}
}
static class1()
{
lockArr = new object();
lockBool = new object();
arr = new ArrayList() { "a", "b", "c", "d", "c", "f", "c" };
Riparti = false;
}
}
}