Salve,
devo creare un nuovo Thread da "Form1" e gestire l'avanzamento della ProgressBar che si trova in "Form1" dal nuovo Thread, come posso fare ???
mi restituisce questo errore:codice:namespace Test_Thread { public partial class Form1 : Form { Thread t; public Form1() { InitializeComponent(); } private void btnStart_Click(object sender, EventArgs e) { DataThread data = new DataThread(progressBar1); t = new Thread(new ParameterizedThreadStart(TestThread)); t.Start(data); } public void TestThread(object data) { if (data != null) { ((DataThread)data).PBar.Maximum = 100; int n = 1000; for (int i = 0; i <= n; i++) { ((DataThread)data).PBar.PerformStep(); } } } } class DataThread { private ProgressBar m_oPb; public DataThread(ProgressBar _oPb) { m_oPb = _oPb; } public ProgressBar PBar { get { return m_oPb; } } } }
Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on.

Rispondi quotando