Thread

SoniqExnihilo Messages postés 25 Date d'inscription vendredi 26 avril 2002 Statut Membre Dernière intervention 16 février 2003 - 14 juin 2002 à 13:21
cs_lapoisse Messages postés 7 Date d'inscription dimanche 19 octobre 2003 Statut Membre Dernière intervention 17 septembre 2005 - 25 mars 2005 à 09:42
juste une question : peut on faire des thread en VB ?

et une deuxieme maintenant : si oui,où dois je regarder pour en savoir plus?

Merci

Soniq Exnihilo

4 réponses

Neo.balastik Messages postés 796 Date d'inscription jeudi 17 mai 2001 Statut Membre Dernière intervention 5 mai 2009 7
14 juin 2002 à 13:39
Salut,

Oui c'est possible mais risqué. VB devient fortement instable lorsqu'il utilise des threads.
Les applications VB utilisant les threads plantent très souvent.

Pour cela, il faut utiliser l'API CreateThread et TerminateThread.

Tchao

NéoB

Voici un exemple repris du site AllApi.net:

'In a module
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public hThread As Long, hThreadID As Long
Public Sub AsyncThread()
'Let this thread sleep for 10 seconds
Sleep 10000
hThread = 0
End Sub

'____________________________________
'In a form
'Add a command button to the form
Private Sub Command1_Click()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'After you click this button, try to move the window
'You will see that the AsyncThread-function was executed asynchronously
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID)
CloseHandle hThread
End Sub
Private Sub Form_Unload(Cancel As Integer)
'If the thread is still running, close it
If hThread <> 0 Then TerminateThread hThread, 0
End Sub
0
SoniqExnihilo Messages postés 25 Date d'inscription vendredi 26 avril 2002 Statut Membre Dernière intervention 16 février 2003
14 juin 2002 à 14:18
hehe . Un grand merci a toi , je v pouvoir enfin m'amuser ;)

Mais là j'appel pas ca gerer par VB vue que c une API . enfin pas grave !! Moult Merci!

Soniq Exnihilo
0
TheSaib Messages postés 2367 Date d'inscription mardi 17 avril 2001 Statut Membre Dernière intervention 26 décembre 2007 23
16 juin 2002 à 16:51
c'est du pseudo thread ... mais c'est la seule maniere
|The S@ib|
VBP2P project
0
cs_lapoisse Messages postés 7 Date d'inscription dimanche 19 octobre 2003 Statut Membre Dernière intervention 17 septembre 2005
25 mars 2005 à 09:42
ça ne marche pas !

Dans l'environnement VB pas de pb
MAIS quand tu compiles un exe alors ça plante :

___________________________________________________________________________________________
PROJECT1.EXE - Erreur d'application

X L'instruction à 0x6a8a7339" emploie l'adresse mémoire 0x0000009c". La mémoire ne peut pas être "written".
__________________________________________________________________________________________

dommage ....
0
Rejoignez-nous