Ce code est exécuté de plusieurs façons. Quand il est exécuté par le bouton de formulaire, cela fonctionne (le bouton démarre un thread et dans la boucle il appelle cette méthode = ça marche). MAIS cela ne fonctionne pas quand j'ai un appel à cette méthode de mon BackgroundWorker dans le formulaire.Aidez-moi avec ce CrossThread?
Avec le code suivant:
private void resizeThreadSafe(int width, int height)
{
if (this.form.InvokeRequired)
{
this.form.Invoke(new DelegateSize(resizeThreadSafe),
new object[] { width, height });
}
this.form.Size = new Size(width, height); // problem occurs on this line
this.form.Location = new Point(0, 0); // dummy coordinate
}
ensuite sur la ligne contenant this.form.Size = ...
je reçois l'exception suivante:
InvalidOperationException was unhandled
Cross-thread operation not valid: Control 'Form1' accessed from a thread other
than the thread it was created on.
Pourquoi?