lang:csharp:thread
Ceci est une ancienne révision du document !
Table des matières
Instruction lock
lock
permet d'empêcher deux threads d'exécuter un code entouré de l'objet verrouillé. Attention, lock
distingue uniquement des threads différents. Un lock(x)
dans un lock(x)
dans un même thread ne pose pas de problème, le deuxième lock
n'étant pas bloquant.
Blocage inter-threads
Sans valeur de retour
public static void readControlText(Control varControl) { if (varControl.InvokeRequired) { varControl.Invoke((Action)delegate {readControlText(varControl);})); } else { // Faire ce qu'il faut. } }
Avec valeur de retour
public static string readControlText(Control varControl) { if (varControl.InvokeRequired) { return (string)varControl.Invoke( new Func<String>(() => readControlText(varControl)) ); } else { // Renvoyer ce qu'il faut. return ""; } }
lang/csharp/thread.1542817459.txt.gz · Dernière modification : 2018/11/21 17:24 de root