Arrêter une tache
-
lundi 16 juillet 2012 08:16
Bonjour, j'ai créé plusieurs taches dans mon programme, ces taches ont pour but de créer une petite animation dans un pictureBox. Voici comment sont créées les taches :
Dim t1 As New Task(Sub() anim_t1()) Dim t2 As New Task(Sub() anim_t2())Et voici le contenu des 2 méthodes :
Sub anim_t1() Do While (1) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image1.gif") Thread.Sleep(100) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image2.gif") Thread.Sleep(100) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image3.gif") Thread.Sleep(100) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image4.gif") Thread.Sleep(100) Loop End Sub Sub anim_t2() Do While (1) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image5.gif") Thread.Sleep(100) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image6.gif") Thread.Sleep(100) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image7.gif") Thread.Sleep(100) mon_animation.Load(My.Application.Info.DirectoryPath & "\form4\image_8.gif") Thread.Sleep(100) Loop End SubDonc ici les animations s'exécutent à l'infini lorsque la tache est lancée. Or j'aimerai qu'à l'appui d'un bouton, que l'animation change. Dans mon cas, je lance les taches avec la méthode start(), le soucis c'est que quand je veux lancé la 2ème tache, les animations se superposent, j'ai bien essayé la méthode wait() mais ça n'arréte pas la tache. Quelle méthode faut il utiliser pour arrêter une tache et non la mettre en attente?
Cordialement, maxkun ;)
Toutes les réponses
-
lundi 16 juillet 2012 08:42Modérateur
Bonjour,
Il faut passer par un booléen (le plus souvent un champ d'une classe) que vous tester dans la boucle :
jeContinue = True
Il suffit ensuite dans votre bouton de mettre ce booléen à False.
Do While (jeContinue) ' ... Loop
Cordialement
Gilles TOURREAU - MVP C#
Architecte logiciel/Consultant/Formateur Freelance
Blog : http://gilles.tourreau.fr
- MCPD : Enterprise Developper / Windows Developper 3.5 / ASP .NET 3.5/4.0
- MCITP : SQL Server 2008 Developper
- MCTS : ADO .NET 3.5 / SQL Server 2008 Developper / Windows Forms 3.5 / ASP .NET 3.5/4.0- Marqué comme réponse maxkun lundi 16 juillet 2012 09:00
-
lundi 16 juillet 2012 09:00Merci :)
Cordialement, maxkun ;)
-
lundi 16 juillet 2012 12:32Modérateur
Bonjour,
Eventuellement, j'avais vu plusieurs fois que le contrôle PictureBox serait capable de gérer tout seul les GIFs animés. A tester peut-être...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

