IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Download fichiers avec VB.net


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2012
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Services de proximité

    Informations forums :
    Inscription : Août 2012
    Messages : 74
    Par défaut Download fichiers avec VB.net
    Bonsoir à tous,
    Je suis en train de créer sous vb.net un programme pour télécharger des fichiers. J'ai créer un backgroundworker pour chaque téléchargement. Mon bouton Download lance download1 et download2
    Je voudrais que backgroundworker1 une fois fini retourne dans Download1 et idem pour backgroundworker2.
    J'ai essayé de mettre download1 à la fin de BackgroundWorker1_DoWork mais le programme me dit que la tâche est occupée.
    J'ai essayé en mettant un timer avec ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
                While BackgroundWorker1.IsBusy
                    Application.DoEvents()
                End While
                Download1()
    mais le programme plante si je ferme la fenêtre et ce n'est pas convaincant...
    J'espère que j'ai été assez clair dans mes explications..
    Voici mon code:
    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
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
     
    Imports System.Net
    Imports SimpleDownloadFile
    Public Class Form1
        Dim Repertoire, Identifiant, Password, FichierIni As String
        Dim Url1, Url2, Url3, Url4, Url5 As String
        Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
        Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As System.Text.StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
        Delegate Sub ChangeTextsSafe(ByVal length As Long, ByVal position As Integer, ByVal percent As Integer)
        Delegate Sub DownloadCompleteSafe(ByVal cancelled As Boolean)
        Function EcrireINI(ByVal entete As String, ByVal variable As String, ByVal valeur As String, ByVal fichier As String)
            On Error Resume Next
            valeur = Trim(valeur)
            WritePrivateProfileString(entete, variable, valeur, fichier)
        End Function
        Function LireINI(ByVal Entete As String, ByVal Variable As String, ByVal Ini As String) As String
            Dim Deff As String = ""
            Try
                Dim StrBuild As New System.Text.StringBuilder(90)
                Dim Ret As Integer = GetPrivateProfileString(Entete, Variable, Deff, StrBuild, 90, Ini)
                Return Trim(StrBuild.ToString)
            Catch
                Return Trim(Deff)
            End Try
        End Function
        Sub AfficherMasquerDownload(ByVal Download As Integer, ByVal Afficher As Integer)
            Select Case Download
                Case 1
                    Select Case Afficher
                        Case 0
                            TexteUrl1.Visible = False
                            TexteSize1.Visible = False
                            Size1.Visible = False
                            Index1.Visible = False
                            TexteDownload1.Visible = False
                            Down1.Visible = False
                            Pourcentage1.Visible = False
                            ProgressBar1.Visible = False
                        Case 1
                            TexteUrl1.Visible = True
                            TexteSize1.Visible = True
                            Size1.Visible = True
                            Index1.Visible = True
                            TexteDownload1.Visible = True
                            Down1.Visible = True
                            Pourcentage1.Visible = True
                            ProgressBar1.Visible = True
                    End Select
                Case 2
                    Select Case Afficher
                        Case 0
                            TexteUrl2.Visible = False
                            TexteSize2.Visible = False
                            Size2.Visible = False
                            Index2.Visible = False
                            TexteDownload2.Visible = False
                            Down2.Visible = False
                            Pourcentage2.Visible = False
                            ProgressBar2.Visible = False
                        Case 1
                            TexteUrl2.Visible = True
                            TexteSize2.Visible = True
                            Size2.Visible = True
                            Index2.Visible = True
                            TexteDownload2.Visible = True
                            Down2.Visible = True
                            Pourcentage2.Visible = True
                            ProgressBar2.Visible = True
                    End Select
            End Select
        End Sub
        Private Sub Download1()
            Dim Absent As Boolean
            Dim Fichier As String = Nothing
            Dim Rep As String = Nothing
            For Compte = 0 To ListView1.Items.Count - 1
                Url1 = ListView1.Items(Compte).Text
                If Url1 <> Url2 And Url1 <> Url3 And Url1 <> Url4 And Url1 <> Url5 Then
                    Dim pos As Integer = Url1.LastIndexOf("/")
                    Dim T = LireINI("Menu", Str(Compte + 1), FichierIni)
                    Dim W As String = T.Substring(Len(T) - 2)
                    If W = "*1" Then
                        Absent = False
                    Else
                        Absent = True
                        AfficherMasquerDownload(1, 1) '<=Modifier
                        ListView1.Items(Compte).ForeColor = Color.Red '<=Modifier
                        ListView1.Items(Compte).BackColor = Color.Yellow '<=Modifier
                        Index1.Text = Compte '<=Modifier(Label Index)
                        Exit For
                    End If
                End If
            Next
            If Absent = True Then
                TexteUrl1.Text = Url1
                Rep = TexteUrl1.Text.Substring(7)
                Rep = Repertoire & Microsoft.VisualBasic.Left(Rep, Rep.LastIndexOf("/")) & "\"
                System.IO.Directory.CreateDirectory(Rep)
                Fichier = TexteUrl1.Text.Substring(TexteUrl1.Text.LastIndexOf("/") + 1)
                BackgroundWorker1.RunWorkerAsync(New Object() {Rep & Fichier})
            End If
        End Sub
        Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            Dim Fichier As String = e.Argument(0)
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Dim Credit As NetworkCredential = New NetworkCredential(Identifiant, Password)
            Try 'Checks if the file exist
                ' theRequest.Credentials = Credit
                theRequest = WebRequest.Create(TexteUrl1.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete1)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End Try
            Dim length As Integer = theResponse.ContentLength 'Size of the response (in bytes)
            Dim safedelegate As New ChangeTextsSafe(AddressOf ProgressDownload1)
            Me.Invoke(safedelegate, length, 0, 0) 'Invoke the TreadsafeDelegate
            Dim writeStream As New IO.FileStream(Fichier, IO.FileMode.Create)
            Dim nRead As Integer
            Dim readings As Integer = 0
            Do
                If BackgroundWorker1.CancellationPending Then 'If user abort download
                    Exit Do
                End If
                Dim readBytes(4095) As Byte
                Dim bytesread As Short = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                Dim percent As Integer = CInt(((nRead / 1024) * 100) / (length / 1024))
                Me.Invoke(safedelegate, length, nRead, percent)
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
                readings += 1
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            If Me.BackgroundWorker1.CancellationPending Then
                IO.File.Delete(Fichier)
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete1)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End If
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete1)
            Me.Invoke(completeDelegate, False)
        End Sub
        Public Sub ProgressDownload1(ByVal length As Integer, ByVal position As Integer, ByVal percent As Integer)
            Size1.Text = Math.Round((length / 1024 / 1024), 2) & " MO"
            Down1.Text = Math.Round((position / 1024 / 1024), 2) & " MO"
            Me.ProgressBar1.Value = percent
            Pourcentage1.Text = percent & " %"
        End Sub
        Public Sub DownloadComplete1(ByVal cancelled As Boolean)
            TexteUrl1.Text = ""
            Down1.Text = ""
            Pourcentage1.Text = ""
            ProgressBar1.Value = 0
            Dim Index As Integer = Val(Index1.Text) + 1
            If cancelled = False Then : EcrireINI("Menu", Str(Index), LireINI("Menu", Str(Index), FichierIni) & "*1", FichierIni) : End If
            ListView1.Items(Index - 1).ForeColor = Color.Lime '<=Modifier
            ListView1.Items(Index - 1).BackColor = Color.Teal '<=Modifier
            Dim a As Integer = Val(Label2.Text) + 1
            Label2.Text = a
            AfficherMasquerDownload(1, 0)
        End Sub
        Private Sub Download2()
            Dim Absent As Boolean
            Dim Fichier As String = Nothing
            Dim Rep As String = Nothing
            For Compte = 0 To ListView1.Items.Count - 1
                Url2 = ListView1.Items(Compte).Text
                If Url2 <> Url1 And Url2 <> Url3 And Url2 <> Url4 And Url2 <> Url5 Then
                    Dim pos As Integer = Url1.LastIndexOf("/")
                    Dim T = LireINI("Menu", Str(Compte + 1), FichierIni)
                    Dim W As String = T.Substring(Len(T) - 2)
                    If W = "*1" Then
                        Absent = False
                    Else
                        Absent = True
                        AfficherMasquerDownload(2, 1) '<=Modifier
                        ListView1.Items(Compte).ForeColor = Color.Red '<=Modifier
                        ListView1.Items(Compte).BackColor = Color.Yellow '<=Modifier
                        Index2.Text = Compte '<=Modifier(Label Index)
                        Exit For
                    End If
                End If
            Next
            If Absent = True Then
                TexteUrl2.Text = Url2
                Rep = TexteUrl2.Text.Substring(7)
                Rep = Repertoire & Microsoft.VisualBasic.Left(Rep, Rep.LastIndexOf("/")) & "\"
                System.IO.Directory.CreateDirectory(Rep)
                Fichier = TexteUrl2.Text.Substring(TexteUrl2.Text.LastIndexOf("/") + 1)
                BackgroundWorker2.RunWorkerAsync(New Object() {Rep & Fichier})
                While BackgroundWorker2.IsBusy
                    Application.DoEvents()
                End While
                Download2()
            End If
        End Sub
        Private Sub BackgroundWorker2_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
            Dim Fichier As String = e.Argument(0)
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Dim Credit As NetworkCredential = New NetworkCredential(Identifiant, Password)
            Try
                ' theRequest.Credentials = Credit
                theRequest = WebRequest.Create(TexteUrl1.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete2)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End Try
            Dim length As Integer = theResponse.ContentLength
            Dim safedelegate As New ChangeTextsSafe(AddressOf ProgressDownload2)
            Me.Invoke(safedelegate, length, 0, 0)
            Dim writeStream As New IO.FileStream(Fichier, IO.FileMode.Create)
            Dim nRead As Integer
            Dim readings As Integer = 0
            Do
                If BackgroundWorker2.CancellationPending Then
                    Exit Do
                End If
                Dim readBytes(4095) As Byte
                Dim bytesread As Short = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                Dim percent As Integer = CInt(((nRead / 1024) * 100) / (length / 1024))
                Me.Invoke(safedelegate, length, nRead, percent)
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
                readings += 1
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            If Me.BackgroundWorker2.CancellationPending Then
                IO.File.Delete(Fichier)
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete2)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End If
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete2)
            Me.Invoke(completeDelegate, False)
        End Sub
        Public Sub ProgressDownload2(ByVal length As Integer, ByVal position As Integer, ByVal percent As Integer)
            Size2.Text = Math.Round((length / 1024 / 1024), 2) & " MO"
            Down2.Text = Math.Round((position / 1024 / 1024), 2) & " MO"
            ProgressBar2.Value = percent
            Pourcentage2.Text = percent & " %"
        End Sub
        Public Sub DownloadComplete2(ByVal cancelled As Boolean)
            TexteUrl2.Text = ""
            Down2.Text = ""
            Pourcentage2.Text = ""
            ProgressBar2.Value = 0
            Dim Index As Integer = Val(Index2.Text) + 1
            If cancelled = False Then : EcrireINI("Menu", Str(Index), LireINI("Menu", Str(Index), FichierIni) & "*1", FichierIni) : End If
            ListView1.Items(Index - 1).ForeColor = Color.Lime '<=Modifier
            ListView1.Items(Index - 1).BackColor = Color.Teal '<=Modifier
            Dim a As Integer = Val(Label2.Text) + 1
            Label2.Text = a
            AfficherMasquerDownload(2, 0)
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AfficherMasquerDownload(1, 0)
            Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
            MyFolderBrowser.Description = "Selectionnez le répertoire de destination:"
            MyFolderBrowser.SelectedPath = "E:\"
            Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
            If dlgResult = Windows.Forms.DialogResult.OK Then
                Repertoire = MyFolderBrowser.SelectedPath + "\"
            End If
            FichierIni = Repertoire & "Fichiers.ini"
            Dim Nombre As Integer = Val(LireINI("Menu", "Nombre", FichierIni))
            Label3.Text = Nombre
            ListView1.Focus()
            Dim Url1 As String
            For Compte = 0 To Nombre - 1
                Url1 = LireINI("Menu", Str(Compte + 1), FichierIni)
                Dim pos As Integer = Url1.LastIndexOf("*")
                If Microsoft.VisualBasic.Right(Url1, 2) = "*1" Then
                    If pos > 0 Then : Url1 = Microsoft.VisualBasic.Left(Url1, pos) : End If
                    ListView1.Items.Add(Url1)
                    Dim a As Integer = Val(Label2.Text) + 1
                    Label2.Text = a
                    ListView1.Items(Compte).Selected = True
                    ListView1.Items(Compte).ForeColor = Color.Lime
                Else
                    ListView1.Items.Add(Url1)
                End If
            Next
            If ListView1.Items.Count > 0 Then
                ListView1.MultiSelect = False
                ListView1.Items(0).Focused = True
                ListView1.Items(0).Selected = True
            End If
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Download1()
            Download2()
        End Sub
    End Class
    Merci à vous tous de bien vouloir m'éclairer...

  2. #2
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 204
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 204
    Par défaut
    le backgroundworker a un évènement levé à la fin du traitement
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2012
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Services de proximité

    Informations forums :
    Inscription : Août 2012
    Messages : 74
    Par défaut
    Qu'es-ce que tu entends par là? Je ne te suis pas...
    Je viens de modifier mon code avec un timer. Ce que je ne comprends pas, j'ai déclaré cinq téléchargements mais j'en ai que deux qui tourne en même temps. J'ai surement du faire une erreur.
    Voici mon code:
    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
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
     
    Imports System.Net
    Imports SimpleDownloadFile
    Public Class Form1
        Dim Repertoire, Identifiant, Password, FichierIni As String
        Dim Url1, Url2, Url3, Url4, Url5 As String
        Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
        Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As System.Text.StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
        Delegate Sub ChangeTextsSafe(ByVal length As Long, ByVal position As Integer, ByVal percent As Integer)
        Delegate Sub DownloadCompleteSafe(ByVal cancelled As Boolean)
        Function EcrireINI(ByVal entete As String, ByVal variable As String, ByVal valeur As String, ByVal fichier As String)
            On Error Resume Next
            valeur = Trim(valeur)
            WritePrivateProfileString(entete, variable, valeur, fichier)
        End Function
        Function LireINI(ByVal Entete As String, ByVal Variable As String, ByVal Ini As String) As String
            Dim Deff As String = ""
            Try
                Dim StrBuild As New System.Text.StringBuilder(90)
                Dim Ret As Integer = GetPrivateProfileString(Entete, Variable, Deff, StrBuild, 90, Ini)
                Return Trim(StrBuild.ToString)
            Catch
                Return Trim(Deff)
            End Try
        End Function
        Sub AfficherMasquerDownload(ByVal Download As Integer, ByVal Afficher As Integer)
            Select Case Download
                Case 1
                    If Afficher = 0 Then : TexteUrl1.Visible = False : Else : TexteUrl1.Visible = True : End If
                    If Afficher = 0 Then : TexteSize1.Visible = False : Else : TexteSize1.Visible = True : End If
                    If Afficher = 0 Then : Size1.Visible = False : Else : Size1.Visible = True : End If
                    If Afficher = 0 Then : Index1.Visible = False : Else : Index1.Visible = True : End If
                    If Afficher = 0 Then : TexteDownload1.Visible = False : Else : TexteDownload1.Visible = True : End If
                    If Afficher = 0 Then : Down1.Visible = False : Else : Down1.Visible = True : End If
                    If Afficher = 0 Then : Pourcentage1.Visible = False : Else : Pourcentage1.Visible = True : End If
                    If Afficher = 0 Then : ProgressBar1.Visible = False : Else : ProgressBar1.Visible = True : End If
                Case 2
                    If Afficher = 0 Then : TexteUrl2.Visible = False : Else : TexteUrl2.Visible = True : End If
                    If Afficher = 0 Then : TexteSize2.Visible = False : Else : TexteSize2.Visible = True : End If
                    If Afficher = 0 Then : Size2.Visible = False : Else : Size2.Visible = True : End If
                    If Afficher = 0 Then : Index2.Visible = False : Else : Index2.Visible = True : End If
                    If Afficher = 0 Then : TexteDownload2.Visible = False : Else : TexteDownload2.Visible = True : End If
                    If Afficher = 0 Then : Down2.Visible = False : Else : Down2.Visible = True : End If
                    If Afficher = 0 Then : Pourcentage2.Visible = False : Else : Pourcentage2.Visible = True : End If
                    If Afficher = 0 Then : ProgressBar2.Visible = False : Else : ProgressBar2.Visible = True : End If
                Case 3
                    If Afficher = 0 Then : TexteUrl3.Visible = False : Else : TexteUrl3.Visible = True : End If
                    If Afficher = 0 Then : TexteSize3.Visible = False : Else : TexteSize3.Visible = True : End If
                    If Afficher = 0 Then : Size3.Visible = False : Else : Size3.Visible = True : End If
                    If Afficher = 0 Then : Index3.Visible = False : Else : Index3.Visible = True : End If
                    If Afficher = 0 Then : TexteDownload3.Visible = False : Else : TexteDownload3.Visible = True : End If
                    If Afficher = 0 Then : Down3.Visible = False : Else : Down3.Visible = True : End If
                    If Afficher = 0 Then : Pourcentage3.Visible = False : Else : Pourcentage3.Visible = True : End If
                    If Afficher = 0 Then : ProgressBar3.Visible = False : Else : ProgressBar3.Visible = True : End If
                Case 4
                    If Afficher = 0 Then : TexteUrl4.Visible = False : Else : TexteUrl4.Visible = True : End If
                    If Afficher = 0 Then : TexteSize4.Visible = False : Else : TexteSize4.Visible = True : End If
                    If Afficher = 0 Then : Size4.Visible = False : Else : Size4.Visible = True : End If
                    If Afficher = 0 Then : Index4.Visible = False : Else : Index4.Visible = True : End If
                    If Afficher = 0 Then : TexteDownload4.Visible = False : Else : TexteDownload4.Visible = True : End If
                    If Afficher = 0 Then : Down4.Visible = False : Else : Down4.Visible = True : End If
                    If Afficher = 0 Then : Pourcentage4.Visible = False : Else : Pourcentage4.Visible = True : End If
                    If Afficher = 0 Then : ProgressBar4.Visible = False : Else : ProgressBar4.Visible = True : End If
                Case 5
                    If Afficher = 0 Then : TexteUrl5.Visible = False : Else : TexteUrl5.Visible = True : End If
                    If Afficher = 0 Then : TexteSize5.Visible = False : Else : TexteSize5.Visible = True : End If
                    If Afficher = 0 Then : Size5.Visible = False : Else : Size5.Visible = True : End If
                    If Afficher = 0 Then : Index5.Visible = False : Else : Index5.Visible = True : End If
                    If Afficher = 0 Then : TexteDownload5.Visible = False : Else : TexteDownload5.Visible = True : End If
                    If Afficher = 0 Then : Down5.Visible = False : Else : Down5.Visible = True : End If
                    If Afficher = 0 Then : Pourcentage5.Visible = False : Else : Pourcentage5.Visible = True : End If
                    If Afficher = 0 Then : ProgressBar5.Visible = False : Else : ProgressBar5.Visible = True : End If
            End Select
        End Sub
        Private Sub Download1()
            Dim Absent As Boolean
            Dim Fichier As String = Nothing
            Dim Rep As String = Nothing
            Timer1.Stop()
            For Compte = 0 To ListView1.Items.Count - 1
                Url1 = ListView1.Items(Compte).Text
                If Url1 <> Url2 And Url1 <> Url3 And Url1 <> Url4 And Url1 <> Url5 Then
                    Dim pos As Integer = Url1.LastIndexOf("/")
                    Dim T = LireINI("Menu", Str(Compte + 1), FichierIni)
                    Dim W As String = T.Substring(Len(T) - 2)
                    If W = "*1" Then
                        Absent = False
                    Else
                        Absent = True
                        AfficherMasquerDownload(1, 1) '<=Modifier
                        ListView1.Items(Compte).ForeColor = Color.Red '<=Modifier
                        ListView1.Items(Compte).BackColor = Color.Yellow '<=Modifier
                        Index1.Text = Compte '<=Modifier(Label Index)
                        Exit For
                    End If
                End If
            Next
            If Absent = True Then
                Timer1.Start()
                TexteUrl1.Text = Url1
                Rep = TexteUrl1.Text.Substring(7)
                Rep = Repertoire & Microsoft.VisualBasic.Left(Rep, Rep.LastIndexOf("/")) & "\"
                System.IO.Directory.CreateDirectory(Rep)
                Fichier = TexteUrl1.Text.Substring(TexteUrl1.Text.LastIndexOf("/") + 1)
                BackgroundWorker1.RunWorkerAsync(New Object() {Rep & Fichier})
            End If
        End Sub
        Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            Dim Fichier As String = e.Argument(0)
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Dim Credit As NetworkCredential = New NetworkCredential(Identifiant, Password)
            Try 'Checks if the file exist
                ' theRequest.Credentials = Credit
                theRequest = WebRequest.Create(TexteUrl1.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete1)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End Try
            Dim length As Integer = theResponse.ContentLength 'Size of the response (in bytes)
            Dim safedelegate As New ChangeTextsSafe(AddressOf ProgressDownload1)
            Me.Invoke(safedelegate, length, 0, 0) 'Invoke the TreadsafeDelegate
            Dim writeStream As New IO.FileStream(Fichier, IO.FileMode.Create)
            Dim nRead As Integer
            Dim readings As Integer = 0
            Do
                If BackgroundWorker1.CancellationPending Then 'If user abort download
                    Exit Do
                End If
                Dim readBytes(4095) As Byte
                Dim bytesread As Short = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                Dim percent As Integer = CInt(((nRead / 1024) * 100) / (length / 1024))
                Me.Invoke(safedelegate, length, nRead, percent)
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
                readings += 1
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            If Me.BackgroundWorker1.CancellationPending Then
                IO.File.Delete(Fichier)
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete1)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End If
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete1)
            Me.Invoke(completeDelegate, False)
        End Sub
        Public Sub ProgressDownload1(ByVal length As Integer, ByVal position As Integer, ByVal percent As Integer)
            Size1.Text = Math.Round((length / 1024 / 1024), 2) & " MO"
            Down1.Text = Math.Round((position / 1024 / 1024), 2) & " MO"
            Me.ProgressBar1.Value = percent
            Pourcentage1.Text = percent & " %"
        End Sub
        Public Sub DownloadComplete1(ByVal cancelled As Boolean)
            TexteUrl1.Text = ""
            Down1.Text = ""
            Pourcentage1.Text = ""
            ProgressBar1.Value = 0
            Dim Index As Integer = Val(Index1.Text) + 1
            If cancelled = False Then : EcrireINI("Menu", Str(Index), LireINI("Menu", Str(Index), FichierIni) & "*1", FichierIni) : End If
            ListView1.Items(Index - 1).ForeColor = Color.Lime '<=Modifier
            ListView1.Items(Index - 1).BackColor = Color.Teal '<=Modifier
            Dim a As Integer = Val(Label2.Text) + 1
            Label2.Text = a
            AfficherMasquerDownload(1, 0)
        End Sub
        Private Sub Download2()
            Dim Absent As Boolean
            Dim Fichier As String = Nothing
            Dim Rep As String = Nothing
            Timer1.Stop()
            For Compte = 0 To ListView1.Items.Count - 1
                Url2 = ListView1.Items(Compte).Text
                If Url2 <> Url1 And Url2 <> Url3 And Url2 <> Url4 And Url2 <> Url5 Then
                    Dim pos As Integer = Url1.LastIndexOf("/")
                    Dim T = LireINI("Menu", Str(Compte + 1), FichierIni)
                    Dim W As String = T.Substring(Len(T) - 2)
                    If W = "*1" Then
                        Absent = False
                    Else
                        Absent = True
                        AfficherMasquerDownload(2, 1) '<=Modifier
                        ListView1.Items(Compte).ForeColor = Color.Red '<=Modifier
                        ListView1.Items(Compte).BackColor = Color.Yellow '<=Modifier
                        Index2.Text = Compte '<=Modifier(Label Index)
                        Exit For
                    End If
                End If
            Next
            If Absent = True Then
                Timer1.Start()
                TexteUrl2.Text = Url2
                Rep = TexteUrl2.Text.Substring(7)
                Rep = Repertoire & Microsoft.VisualBasic.Left(Rep, Rep.LastIndexOf("/")) & "\"
                System.IO.Directory.CreateDirectory(Rep)
                Fichier = TexteUrl2.Text.Substring(TexteUrl2.Text.LastIndexOf("/") + 1)
                BackgroundWorker2.RunWorkerAsync(New Object() {Rep & Fichier})
            End If
        End Sub
        Private Sub BackgroundWorker2_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
            Dim Fichier As String = e.Argument(0)
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Dim Credit As NetworkCredential = New NetworkCredential(Identifiant, Password)
            Try
                ' theRequest.Credentials = Credit
                theRequest = WebRequest.Create(TexteUrl1.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete2)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End Try
            Dim length As Integer = theResponse.ContentLength
            Dim safedelegate As New ChangeTextsSafe(AddressOf ProgressDownload2)
            Me.Invoke(safedelegate, length, 0, 0)
            Dim writeStream As New IO.FileStream(Fichier, IO.FileMode.Create)
            Dim nRead As Integer
            Dim readings As Integer = 0
            Do
                If BackgroundWorker2.CancellationPending Then
                    Exit Do
                End If
                Dim readBytes(4095) As Byte
                Dim bytesread As Short = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                Dim percent As Integer = CInt(((nRead / 1024) * 100) / (length / 1024))
                Me.Invoke(safedelegate, length, nRead, percent)
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
                readings += 1
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            If Me.BackgroundWorker2.CancellationPending Then
                IO.File.Delete(Fichier)
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete2)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End If
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete2)
            Me.Invoke(completeDelegate, False)
        End Sub
        Public Sub ProgressDownload2(ByVal length As Integer, ByVal position As Integer, ByVal percent As Integer)
            Size2.Text = Math.Round((length / 1024 / 1024), 2) & " MO"
            Down2.Text = Math.Round((position / 1024 / 1024), 2) & " MO"
            ProgressBar2.Value = percent
            Pourcentage2.Text = percent & " %"
        End Sub
        Public Sub DownloadComplete2(ByVal cancelled As Boolean)
            TexteUrl2.Text = ""
            Down2.Text = ""
            Pourcentage2.Text = ""
            ProgressBar2.Value = 0
            Dim Index As Integer = Val(Index2.Text) + 1
            If cancelled = False Then : EcrireINI("Menu", Str(Index), LireINI("Menu", Str(Index), FichierIni) & "*1", FichierIni) : End If
            ListView1.Items(Index - 1).ForeColor = Color.Lime '<=Modifier
            ListView1.Items(Index - 1).BackColor = Color.Teal '<=Modifier
            Dim a As Integer = Val(Label2.Text) + 1
            Label2.Text = a
            AfficherMasquerDownload(2, 0)
        End Sub
        Private Sub Download3()
            Dim Absent As Boolean
            Dim Fichier As String = Nothing
            Dim Rep As String = Nothing
            Timer1.Stop()
            For Compte = 0 To ListView1.Items.Count - 1
                Url3 = ListView1.Items(Compte).Text
                If Url3 <> Url1 And Url3 <> Url2 And Url3 <> Url4 And Url3 <> Url5 Then
                    Dim pos As Integer = Url3.LastIndexOf("/")
                    Dim T = LireINI("Menu", Str(Compte + 1), FichierIni)
                    Dim W As String = T.Substring(Len(T) - 2)
                    If W = "*1" Then
                        Absent = False
                    Else
                        Absent = True
                        AfficherMasquerDownload(3, 1) '<=Modifier
                        ListView1.Items(Compte).ForeColor = Color.Red '<=Modifier
                        ListView1.Items(Compte).BackColor = Color.Yellow '<=Modifier
                        Index3.Text = Compte '<=Modifier(Label Index)
                        Exit For
                    End If
                End If
            Next
            If Absent = True Then
                Timer1.Start()
                TexteUrl3.Text = Url3
                Rep = TexteUrl3.Text.Substring(7)
                Rep = Repertoire & Microsoft.VisualBasic.Left(Rep, Rep.LastIndexOf("/")) & "\"
                System.IO.Directory.CreateDirectory(Rep)
                Fichier = TexteUrl3.Text.Substring(TexteUrl3.Text.LastIndexOf("/") + 1)
                BackgroundWorker3.RunWorkerAsync(New Object() {Rep & Fichier})
            End If
        End Sub
        Private Sub BackgroundWorker3_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker3.DoWork
            Dim Fichier As String = e.Argument(0)
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Dim Credit As NetworkCredential = New NetworkCredential(Identifiant, Password)
            Try
                ' theRequest.Credentials = Credit
                theRequest = WebRequest.Create(TexteUrl3.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete3)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End Try
            Dim length As Integer = theResponse.ContentLength
            Dim safedelegate As New ChangeTextsSafe(AddressOf ProgressDownload3)
            Me.Invoke(safedelegate, length, 0, 0)
            Dim writeStream As New IO.FileStream(Fichier, IO.FileMode.Create)
            Dim nRead As Integer
            Dim readings As Integer = 0
            Do
                If BackgroundWorker3.CancellationPending Then
                    Exit Do
                End If
                Dim readBytes(4095) As Byte
                Dim bytesread As Short = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                Dim percent As Integer = CInt(((nRead / 1024) * 100) / (length / 1024))
                Me.Invoke(safedelegate, length, nRead, percent)
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
                readings += 1
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            If Me.BackgroundWorker3.CancellationPending Then
                IO.File.Delete(Fichier)
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete3)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End If
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete3)
            Me.Invoke(completeDelegate, False)
        End Sub
        Public Sub ProgressDownload3(ByVal length As Integer, ByVal position As Integer, ByVal percent As Integer)
            Size3.Text = Math.Round((length / 1024 / 1024), 2) & " MO"
            Down3.Text = Math.Round((position / 1024 / 1024), 2) & " MO"
            ProgressBar3.Value = percent
            Pourcentage3.Text = percent & " %"
        End Sub
        Public Sub DownloadComplete3(ByVal cancelled As Boolean)
            TexteUrl3.Text = ""
            Down3.Text = ""
            Pourcentage3.Text = ""
            ProgressBar3.Value = 0
            Dim Index As Integer = Val(Index3.Text) + 1
            If cancelled = False Then : EcrireINI("Menu", Str(Index), LireINI("Menu", Str(Index), FichierIni) & "*1", FichierIni) : End If
            ListView1.Items(Index - 1).ForeColor = Color.Lime '<=Modifier
            ListView1.Items(Index - 1).BackColor = Color.Teal '<=Modifier
            Dim a As Integer = Val(Label2.Text) + 1
            Label2.Text = a
            AfficherMasquerDownload(3, 0)
        End Sub
        Private Sub Download4()
            Dim Absent As Boolean
            Dim Fichier As String = Nothing
            Dim Rep As String = Nothing
            Timer1.Stop()
            For Compte = 0 To ListView1.Items.Count - 1
                Url4 = ListView1.Items(Compte).Text
                If Url4 <> Url1 And Url4 <> Url2 And Url4 <> Url3 And Url4 <> Url5 Then
                    Dim pos As Integer = Url4.LastIndexOf("/")
                    Dim T = LireINI("Menu", Str(Compte + 1), FichierIni)
                    Dim W As String = T.Substring(Len(T) - 2)
                    If W = "*1" Then
                        Absent = False
                    Else
                        Absent = True
                        AfficherMasquerDownload(4, 1)
                        ListView1.Items(Compte).ForeColor = Color.Red
                        ListView1.Items(Compte).BackColor = Color.Yellow
                        Index4.Text = Compte '<=Modifier(Label Index)
                        Exit For
                    End If
                End If
            Next
            If Absent = True Then
                Timer1.Start()
                TexteUrl4.Text = Url4
                Rep = TexteUrl4.Text.Substring(7)
                Rep = Repertoire & Microsoft.VisualBasic.Left(Rep, Rep.LastIndexOf("/")) & "\"
                System.IO.Directory.CreateDirectory(Rep)
                Fichier = TexteUrl4.Text.Substring(TexteUrl4.Text.LastIndexOf("/") + 1)
                BackgroundWorker4.RunWorkerAsync(New Object() {Rep & Fichier})
            End If
        End Sub
        Private Sub BackgroundWorker4_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker4.DoWork
            Dim Fichier As String = e.Argument(0)
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Dim Credit As NetworkCredential = New NetworkCredential(Identifiant, Password)
            Try
                ' theRequest.Credentials = Credit
                theRequest = WebRequest.Create(TexteUrl4.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete4)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End Try
            Dim length As Integer = theResponse.ContentLength
            Dim safedelegate As New ChangeTextsSafe(AddressOf ProgressDownload4)
            Me.Invoke(safedelegate, length, 0, 0)
            Dim writeStream As New IO.FileStream(Fichier, IO.FileMode.Create)
            Dim nRead As Integer
            Dim readings As Integer = 0
            Do
                If BackgroundWorker4.CancellationPending Then
                    Exit Do
                End If
                Dim readBytes(4095) As Byte
                Dim bytesread As Short = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                Dim percent As Integer = CInt(((nRead / 1024) * 100) / (length / 1024))
                Me.Invoke(safedelegate, length, nRead, percent)
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
                readings += 1
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            If Me.BackgroundWorker4.CancellationPending Then
                IO.File.Delete(Fichier)
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete4)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End If
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete4)
            Me.Invoke(completeDelegate, False)
        End Sub
        Public Sub ProgressDownload4(ByVal length As Integer, ByVal position As Integer, ByVal percent As Integer)
            Size4.Text = Math.Round((length / 1024 / 1024), 2) & " MO"
            Down4.Text = Math.Round((position / 1024 / 1024), 2) & " MO"
            ProgressBar4.Value = percent
            Pourcentage4.Text = percent & " %"
        End Sub
        Public Sub DownloadComplete4(ByVal cancelled As Boolean)
            TexteUrl4.Text = ""
            Down4.Text = ""
            Pourcentage4.Text = ""
            ProgressBar4.Value = 0
            Dim Index As Integer = Val(Index4.Text) + 1
            If cancelled = False Then : EcrireINI("Menu", Str(Index), LireINI("Menu", Str(Index), FichierIni) & "*1", FichierIni) : End If
            ListView1.Items(Index - 1).ForeColor = Color.Lime '<=Modifier
            ListView1.Items(Index - 1).BackColor = Color.Teal '<=Modifier
            Dim a As Integer = Val(Label2.Text) + 1
            Label2.Text = a
            AfficherMasquerDownload(4, 0)
        End Sub
        Private Sub Download5()
            Dim Absent As Boolean
            Dim Fichier As String = Nothing
            Dim Rep As String = Nothing
            Timer1.Stop()
            For Compte = 0 To ListView1.Items.Count - 1
                Url5 = ListView1.Items(Compte).Text
                If Url5 <> Url1 And Url5 <> Url2 And Url5 <> Url3 And Url5 <> Url4 Then
                    Dim pos As Integer = Url5.LastIndexOf("/")
                    Dim T = LireINI("Menu", Str(Compte + 1), FichierIni)
                    Dim W As String = T.Substring(Len(T) - 2)
                    If W = "*1" Then
                        Absent = False
                    Else
                        Absent = True
                        AfficherMasquerDownload(5, 1)
                        ListView1.Items(Compte).ForeColor = Color.Red
                        ListView1.Items(Compte).BackColor = Color.Yellow
                        Index5.Text = Compte
                        Exit For
                    End If
                End If
            Next
            If Absent = True Then
                Timer1.Start()
                TexteUrl5.Text = Url5
                Rep = TexteUrl5.Text.Substring(7)
                Rep = Repertoire & Microsoft.VisualBasic.Left(Rep, Rep.LastIndexOf("/")) & "\"
                System.IO.Directory.CreateDirectory(Rep)
                Fichier = TexteUrl5.Text.Substring(TexteUrl5.Text.LastIndexOf("/") + 1)
                BackgroundWorker5.RunWorkerAsync(New Object() {Rep & Fichier})
            End If
        End Sub
        Private Sub BackgroundWorker5_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker5.DoWork
            Dim Fichier As String = e.Argument(0)
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Dim Credit As NetworkCredential = New NetworkCredential(Identifiant, Password)
            Try
                ' theRequest.Credentials = Credit
                theRequest = WebRequest.Create(TexteUrl5.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete5)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End Try
            Dim length As Integer = theResponse.ContentLength
            Dim safedelegate As New ChangeTextsSafe(AddressOf ProgressDownload5)
            Me.Invoke(safedelegate, length, 0, 0)
            Dim writeStream As New IO.FileStream(Fichier, IO.FileMode.Create)
            Dim nRead As Integer
            Dim readings As Integer = 0
            Do
                If BackgroundWorker5.CancellationPending Then
                    Exit Do
                End If
                Dim readBytes(4095) As Byte
                Dim bytesread As Short = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                Dim percent As Integer = CInt(((nRead / 1024) * 100) / (length / 1024))
                Me.Invoke(safedelegate, length, nRead, percent)
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
                readings += 1
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            If BackgroundWorker5.CancellationPending Then
                IO.File.Delete(Fichier)
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete5)
                Me.Invoke(cancelDelegate, True)
                Exit Sub
            End If
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete5)
            Me.Invoke(completeDelegate, False)
        End Sub
        Public Sub ProgressDownload5(ByVal length As Integer, ByVal position As Integer, ByVal percent As Integer)
            Size5.Text = Math.Round((length / 1024 / 1024), 2) & " MO"
            Down5.Text = Math.Round((position / 1024 / 1024), 2) & " MO"
            ProgressBar5.Value = percent
            Pourcentage5.Text = percent & " %"
        End Sub
        Public Sub DownloadComplete5(ByVal cancelled As Boolean)
            TexteUrl5.Text = ""
            Down5.Text = ""
            Pourcentage5.Text = ""
            ProgressBar5.Value = 0
            Dim Index As Integer = Val(Index5.Text) + 1
            If cancelled = False Then : EcrireINI("Menu", Str(Index), LireINI("Menu", Str(Index), FichierIni) & "*1", FichierIni) : End If
            ListView1.Items(Index - 1).ForeColor = Color.Lime '<=Modifier
            ListView1.Items(Index - 1).BackColor = Color.Teal '<=Modifier
            Dim a As Integer = Val(Label2.Text) + 1
            Label2.Text = a
            AfficherMasquerDownload(5, 0)
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AfficherMasquerDownload(1, 0)
            AfficherMasquerDownload(2, 0)
            AfficherMasquerDownload(3, 0)
            AfficherMasquerDownload(4, 0)
            AfficherMasquerDownload(5, 0)
            Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
            MyFolderBrowser.Description = "Selectionnez le répertoire de destination:"
            MyFolderBrowser.SelectedPath = "E:\"
            Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
            If dlgResult = Windows.Forms.DialogResult.OK Then
                Repertoire = MyFolderBrowser.SelectedPath + "\"
            End If
            FichierIni = Repertoire & "Fichiers.ini"
            Dim Nombre As Integer = Val(LireINI("Menu", "Nombre", FichierIni))
            Label3.Text = Nombre
            ListView1.Focus()
            Dim Url1 As String
            For Compte = 0 To Nombre - 1
                Url1 = LireINI("Menu", Str(Compte + 1), FichierIni)
                Dim pos As Integer = Url1.LastIndexOf("*")
                If Microsoft.VisualBasic.Right(Url1, 2) = "*1" Then
                    If pos > 0 Then : Url1 = Microsoft.VisualBasic.Left(Url1, pos) : End If
                    ListView1.Items.Add(Url1)
                    Dim a As Integer = Val(Label2.Text) + 1
                    Label2.Text = a
                    ListView1.Items(Compte).Selected = True
                    ListView1.Items(Compte).ForeColor = Color.Lime
                Else
                    ListView1.Items.Add(Url1)
                End If
            Next
            If ListView1.Items.Count > 0 Then
                ListView1.MultiSelect = False
                ListView1.Items(0).Focused = True
                ListView1.Items(0).Selected = True
            End If
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Download1()
            Download2()
            Download3()
            Download4()
            Download5()
        End Sub
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If BackgroundWorker1.IsBusy Then:Else : Download1():End If
            If BackgroundWorker2.IsBusy Then:Else : Download2():End If
            If BackgroundWorker3.IsBusy Then:Else : Download3():End If
            If BackgroundWorker4.IsBusy Then : Else : Download4() : End If
            If BackgroundWorker5.IsBusy Then : Else : Download5() : End If
        End Sub
    End Class
    Si quelqu'un a une solution autre que le timer je suis preneur...
    Merci.

  4. #4
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 204
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 204
    Par défaut
    ton code est moche et je ne sais pas par ou commencer pour te donner des conseils
    mais un select case avec autant de ligne de code c'est pas génial
    1 backgroundworker c'est pas utile si c'est pour télécharger un fichier, le webclient fait ca très bien en asynchrone (avec report d'avancement aussi)
    et 5 webclient avec chacun leurs méthodes ca ne se fait pas non plus, il faut une méthode pour les 5

    sinon tu nous dis ce que tu veux faire exactement pour qu'on puisse t'aiguiller
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  5. #5
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2012
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Services de proximité

    Informations forums :
    Inscription : Août 2012
    Messages : 74
    Par défaut
    Pardon mais je débute en vb
    Mon but final est de pouvoir télécharger une liste de fichiers. Je voudrais également qu' il télécharge cing fichiers en même temps c'est pour cette raison que j'avais créé cinq backgroundworker.
    J'avais essayé avec un webclient mais j'étais limiter à deux téléchargements à la fois.
    Encore merci de bien vouloir m'aiguiller...

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Février 2006
    Messages
    505
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Février 2006
    Messages : 505
    Par défaut
    Je suis pas un expert mais il me semble que le backgroundworker n'est pas l'outil qu'il te faut pour téléchargé cinq fichiers à la fois, tu serais mieux avec multitreading.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Download fichier avec RPC et DTO
    Par Chritofff dans le forum GWT et Vaadin
    Réponses: 0
    Dernier message: 20/04/2011, 14h43
  2. download fichier avec filereference
    Par ythierrin dans le forum Flex
    Réponses: 5
    Dernier message: 03/03/2009, 11h06
  3. ouvrir un fichier avec asp.net
    Par IcedLand dans le forum ASP.NET
    Réponses: 3
    Dernier message: 23/09/2007, 18h38
  4. download fichier avec espace dans le nom
    Par cb68 dans le forum Langage
    Réponses: 8
    Dernier message: 23/11/2005, 11h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo