Bonjour,

J'ai quelques interrogations concernant l'assignation de paramètres d'un composant winform durant l’exécution d'un thread (ex: backgroundworker).

Je pensais que si on assignait une valeur à un composant winform via un autre thread que celui principal, il y avait une exception.

Pourtant quand j’exécute ce code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
        public Form1()
        {
            InitializeComponent();
 
            BackgroundWorker bw = new BackgroundWorker();
 
            textBox1.Text = "test";
 
 
            bw.DoWork += bw_DoWork;
            bw.RunWorkerAsync();
        }
 
        public void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            do
            {
                string text = textBox1.Text;
                textBox1.Text = "test1";
            }
            while(true);
        }
Il n'y a aucun problème ni pour lire la valeur ni pour l'assigner.

Pourriez vous m’éclairer cette interrogation ?
Merci.
F.