Comment mettre à jour l'interface graphique depuis un autre thread ?
Comment mettre à jour l'interface graphique depuis un autre thread ?
Comment mettre à jour l'interface graphique depuis un autre thread ?
Re: Comment mettre à jour l'interface graphique depuis un autre thread ?
Pour .NET 2.0, voici un bout de code que j'ai écrit qui fait exactement ce que vous voulez, et fonctionne pour n'importe quelle propriété d'un `Control` :
```
private delegate void SetControlPropertyThreadSafeDelegate(
Control control,
string propertyName,
object propertyValue);
public static void SetControlPropertyThreadSafe(
Control control,
string propertyName,
object propertyValue)
{
if (control.InvokeRequired)
{
control.Invoke(new SetControlPropertyThreadSafeDelegate
(SetControlPropertyThreadSafe),
new object[] { control, propertyName, propertyValue });
}
```
private delegate void SetControlPropertyThreadSafeDelegate(
Control control,
string propertyName,
object propertyValue);
public static void SetControlPropertyThreadSafe(
Control control,
string propertyName,
object propertyValue)
{
if (control.InvokeRequired)
{
control.Invoke(new SetControlPropertyThreadSafeDelegate
(SetControlPropertyThreadSafe),
new object[] { control, propertyName, propertyValue });
}