Private Delegate Function DlgMaFonction(ByVal pValue as integer) as string Private Function MaFonction(ByVal pValue as integer) as string If Me.InvokeRequired then Return me.Invoke(new DlgMaFunction(AddressOf MaFonction),new object(){pValue}) End If Return pValue.ToString() End Function
Private Delegate Function DlgMaFonction() Private Function POP_Gmail() If Me.InvokeRequired Then Return Me.Invoke(New DlgMaFonction(AddressOf POP_Gmail), New Object()) End If ' Le code de ma fonction End Function Private Sub BGW2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGW2.DoWork POP_Gmail() End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Form1 Private Delegate Sub MaSubDelegate(ByVal ResultatFonction As Integer) 'nouveau label Dim Label1 As New Label With {.Text "Attente résultat...", .Parent Me, .ForeColor = Color.BlueViolet} Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'lancement du thread BGW2.RunWorkerAsync() End Sub Private Sub BGW2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGW2.DoWork If Me.InvokeRequired Then Me.Invoke(New MaSubDelegate(AddressOf MaSub), Pop_Gmail) End Sub Private Function Pop_Gmail() As Integer 'boucle bidon pour simuler un long calcul For x As Integer = 0 To 900000000 Next 'résultat bidon pour le test Return 456789 End Function Private Sub MaSub(ByVal ResultatFonction As Integer) 'résultat contient le résultat de la fonction Label1.Text = ResultatFonction.ToString End Sub End Class
la fonction utilise d'autres fonctions et à la fin ca fait tout le code de mon projet