Bonjour,

Me voilà confronté à une problématique.
Je réalise un convertisseur wav mp3, ou plutôt une interface graphique conviviale paramétrable qui tire les ficelles sur un programme externe, ici il s'agit de lame.exe .
Je désire convertir plusieurs fichiers audio, et de manière séquentielle, ce qui veut dire appeler N fois le programme externe. Et c'est là que votre aide m'est précieuse
J'effectue mon appel à l'aide de la commande shell en primitive bloquante afin que le traitement s'effectue bien séquentiellement et pour éviter d'avoir N fenêtres de commande qui s'ouvrent d'un coup!

Seulement je crois que cette solution d'appel bloquant empêche à mon application principale de recevoir et traiter les messages de l'OS du style réduire la fenêtre, ou simplement annuler la conversion.

Connaissez vous une solution plus adéquate pour réaliser cette fonctionnalité?
J'ai pensé au threads, mais au final l'application principale devra tout de même "attendre" que la conversion du premier fichier soit terminée avant d'enchainer sur le second.

Voici un extrait du code afin d'éclaircir un peu:


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
    ' shell execute
    Private Sub shellExecute(ByVal cmd As String, ByVal isBlocking As Boolean, ByVal PromptOption As Short)
        ' shell command execute
        Try
            Shell(cmd, PromptOption, isBlocking, -1)
            'Shell(cmd, AppWinStyle.MinimizedNoFocus, True, -1)
        Catch ex As Exception
 
        End Try
    End Sub


Et la fonction qui s'éxécute lorsque je clique sur le bouton de lancement de conversion...

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
' when you click the convert now button!
    Private Sub ConvertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertButton.Click
        Dim count, progress As Integer
        Dim currentFile As String
        Dim InputFilePrefix, TmpFileFullPath, OutFileFullPath, FileOutPath, tmpCmd As String
        Dim FileOutType As String = ".error"    ' will be set according to your settings!
        Dim FileSubNames(3) As String
 
 
        ' first, we check if there's any input file to convert
        If (ListView1.Items.Count = 0) Then
            MessageBox.Show("there's no input file to convert!")
            Return
        Else
            ' set Progress 'maximum' step attribute based on input file number
            ToolStripProgressBar1.Maximum = ListView1.Items.Count
        End If
 
        ' so, there's something to convert
 
 
 
 
        ToolStripProgressBar1.Value = 0
        ' now we need to get all files in ListView1 (if non empty!)
        For count = 0 To ListView1.Items.Count - 1
            currentFile = ListView1.Items(count).SubItems(0).Text()
 
            ' set the bubbleMsg text value
            progress = count / (ListView1.Items.Count - 1) * 100
            bubbleMsg = "job progression: " + progress.ToString
 
            ' prompt for job in progress
            ListView1.Items.Item(count).SubItems.Add("...")
            Application.DoEvents()  ' equals yield() in C (enfin, si j'ai bien compris)
 
            ' Get Input file Basename
            FileSubNames = currentFile.Split(".")
            InputFilePrefix = FileSubNames(0)
 
 
            ' get the output Directory
            If (useCustomOutputDirectory = False) Then
                FileOutPath = Path(count)
            Else
                FileOutPath = DialogGeneralSettings.Label_outputDir.Text
            End If
 
 
            ' define what outputFiles type we want (.mp3 or .wav) depending on Options/<type> convertion checked subItem
            If (MP3ConversionToolStripMenuItem.Checked = True) Then
 
                TmpFileFullPath = FileOutPath + "\" + InputFilePrefix + ".tmp"
                OutFileFullPath = FileOutPath + "\" + InputFilePrefix + ".mp3"
 
                ' first wav to mp3 conversion
                tmpCmd = "lame.exe -h """ + Path(count) + "\" + currentFile + """ """ + TmpFileFullPath + """"
                ToolStripStatusLabel1.Text = "converting " + currentFile + " to MP3 fileType"
                Application.DoEvents()
                shellExecute(tmpCmd, True, showJobStyle)
                ' then bitrate adjustment
                tmpCmd = "lame.exe --mp3input -b" + kbps.ToString + " """ + TmpFileFullPath + """ """ + OutFileFullPath + """"
                ToolStripStatusLabel1.Text = "adjusting " + currentFile + " bitrate to " + kbps.ToString + " Kbps"
                Application.DoEvents()
                shellExecute(tmpCmd, True, showJobStyle)
                ' cleaning intermediate file
                IO.File.Delete(TmpFileFullPath)
 
            ElseIf (WaveConversionToolStripMenuItem.Checked = True) Then
 
                OutFileFullPath = FileOutPath + "\" + InputFilePrefix + ".wav"
 
                'the only one shell command
                tmpCmd = "lame.exe --decode """ + Path(count) + "\" + currentFile + """ """ + OutFileFullPath + """"
                ToolStripStatusLabel1.Text = "converting " + currentFile + " to WAV fileType"
                Application.DoEvents()
 
 
                ' C'est ici que j'ai besoin de votre aide
                '
                '
                shellExecute(tmpCmd, True, showJobStyle)
                '
                '
                '
 
 
 
 
            Else
                MessageBox.Show("No file output type defined, please ensure in 'Options' that either 'MP3 conversion' or 'Wav conversion' is checked")
                Return
            End If
 
            System.Threading.Thread.Sleep(500)  ' sleep 500ms for fun!
 
            ' show end conversion status
            If (IO.File.Exists(OutFileFullPath)) Then
                ListView1.Items.Item(count).SubItems(1).Text = "ok!"
            Else
                ListView1.Items.Item(count).SubItems(1).Text = "Error!"
            End If
 
            ' prompt job evolution
            ToolStripProgressBar1.Increment(1)
            'ListView1.Update()
            Application.DoEvents()  ' equals yield() in C
        Next
 
 
 
        ' ---- here job is done! ----
 
        If (EndJobSoundPlay = True) Then
            If (EndJobSoundFullPath.Contains("\") = True) Then
                My.Computer.Audio.Play(EndJobSoundFullPath)
            Else
                My.Computer.Audio.Play(getAppPath + "\" + EndJobSoundFullPath)
            End If
        End If
 
        ToolStripStatusLabel1.Text = "Job done!"
 
        If (NotifyIcon1.Visible = True) Then
            NotifyIcon1.BalloonTipText = "Job Done :)"
            NotifyIcon1.ShowBalloonTip(3000)
        End If
 
        Application.DoEvents()
 
    End Sub

Merci par avance pour votre aide