Initialisation de la Fenêtre Mère
// On supprime l'ancien Sémaphore si existant
SémaphoreDétruit("SEM_LIMITE")
// On recrée le sémaphore
SémaphoreCrée("SEM_LIMITE",po_NBFEN..Valeur)
// On peut modifier le nombre de thread dans le pool
po_NBFEN..Etat = Actif //po_NBFEN est un POtentiomètre
RepriseSaisie(cs_Adresse)
Click sur bc_Ping
chNomThread est une chaîne
chNomAlias est une chaîne
chCommande est une chaîne
//cs_Adresse est le Champ de Saisie où l'on indique l'adresse à "pinger"
chNomThread="THREAD_"+Remplace(cs_Adresse,".","")
chNomThread=Remplace(chNomThread,"/","")
chNomThread=Remplace(chNomThread,":","")
chNomAlias=Remplace(chNomThread,"THREAD_","FEN_")
//Exemple :
//Pour le Ping de 127.0.0.1 on aura
//FEN_127001 et THREAD_127001
//et www.google.fr donnera
//FEN_wwwgooglefr et THREAD_wwwgooglefr
chCommande="PING "+cs_Adresse+" -t"
SI FenEtat(chNomAlias)=Inexistant ALORS
Sablier(Vrai)
// On ne peut plus modifier le nombre de thread dans le pool
po_NBFEN..Etat = Grisé
// On exécute le thread
ThreadExécute(chNomThread,threadNormal,PL_ThreadPing,chNomAlias,chCommande )
// On attend que le thread se soit lancé
ThreadAttendSignal()
Sablier(Faux)
SINON
MDIActive( Remplace(chNomThread,"THREAD_","FEN_"))
FIN
PROCEDURE PL_ThreadPing(plFen, plCommande)
// On indique que le thread s'est chargé et lancé
ThreadEnvoieSignal(".")
// Contrôle du nombre de thread à un instant t grâce aux sémaphores
SémaphoreDébut("SEM_LIMITE")
SectionCritiqueDébut(plFen)
MDIOuvre(frmMain,plFen, ExtraitChaîne(plFen,1,"_",DepuisFin))
gclMyDos:CommandLine_Let(plCommande)
gclMyDos:ExecuteCommand(plFen)
SectionCritiqueFin(plFen)
Cette contribution était de : http://old.wdforge.org/newbb/viewtopic.php?forum=17&topic_id=5272&post_id=21811