Bonjour,
J'ai un problème de thread qui après son execution les variables qu'il a modifié reviennent à leur valeur d'origine!
mon code de test
dans un module:
dans le formulaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 Imports System.Threading Module Test Private Structure mytab Public filename As String Public width As Integer Public height As Integer Public bmp As Bitmap Public Sub load() bmp = New Bitmap(filename) width = bmp.Width height = bmp.Height filename = "pouet a pouet" MsgBox("dans le thread: H:" & height & ", W:" & width & ", File:" & filename) End Sub End Structure Public Structure Prout Private tab() As mytab Private Inc As Integer Public Sub Add(ByVal filename As String) If tab Is Nothing Then ReDim tab(0) Else ReDim Preserve tab(Inc) End If tab(Inc).filename = filename Dim mythread As Thread = New Thread(AddressOf tab(Inc).load) mythread.Start() Do While mythread.ThreadState <> ThreadState.Stopped Loop MsgBox("Hors du thread: H:" & tab(Inc).height & " W:" & tab(Inc).width & " File:" & tab(Inc).filename) Inc += 1 End Sub End Structure Public Pouet As Prout End Module
Les 2 msgbox affiches des données differente
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Pouet.Add("E:\ressources\back.jpg") End Sub End Class
Partager