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 :

freeze 1 pourcentage dans listview1


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    323
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 323
    Par défaut freeze 1 pourcentage dans listview1
    Bonjour,

    j'ai refait mon code de la class FileDownloader mais ça freeze dans listview1 à 1 % dans le téléchargement du fichier.
    Nom : Capture d’écran 2024-07-31 153010.png
Affichages : 132
Taille : 8,4 Ko

    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
    Imports System.Net
    Imports System.IO
     
    Public Class FileDownloader
     
        Private _Url As String = String.Empty
        Private _DirectoryPath As String = String.Empty
        Public _IsStarted As Boolean = False
        Public Delegate Sub _DownloadStarting(ByVal thread As FileDownloader)
        Public Event DownloadStarting As _DownloadStarting
        Public Delegate Sub ProgressChangedEventHandler(ByVal thread As FileDownloader, ByVal e As DownloadProgressArgs)
        Public Event DownloadProgressChanged As ProgressChangedEventHandler
        Public Delegate Sub DownloadCompletedEventHandler(ByVal thread As FileDownloader, ByVal e As DownloadCompletedArgs)
        Public Event DownloadCompleted As DownloadCompletedEventHandler
     
        Protected Overridable Sub OnDownloadStarting(ByVal thread As FileDownloader)
            RaiseEvent DownloadStarting(Me)
        End Sub
        Protected Overridable Sub OnDownloadProgress(ByVal thread As FileDownloader, ByVal e As DownloadProgressArgs)
            RaiseEvent DownloadProgressChanged(Me, e)
        End Sub
        Protected Overridable Sub OnDownloadCompleted(ByVal thread As FileDownloader, ByVal e As DownloadCompletedArgs)
            RaiseEvent DownloadCompleted(Me, e)
        End Sub
     
        Public Sub New(ByVal Url As String, ByVal directory As String)
            _Url = Url
            _DirectoryPath = directory
        End Sub
     
        Public Sub StartDownload()
            If String.IsNullOrEmpty(_Url) Then
                Throw New ArgumentException("Veuillez fournir un URL.")
            End If
            If String.IsNullOrEmpty(_DirectoryPath) Then
                Throw New ArgumentException("Veuillez fournir une destination.")
            End If
            _IsStarted = True
            OnDownloadStarting(Me)
            Try
                Dim request As HttpWebRequest = CType(WebRequest.Create(New Uri(_Url)), HttpWebRequest)
                With request
                    .Referer = _Url.ToString
                    .Method = "GET"
                    .UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0"
                    .ContentType = "application/octet-stream"
                    .Accept = "*/*"
                    .Timeout = 3000
                    .AllowAutoRedirect = True
                End With
                Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
                    If response.StatusCode = HttpStatusCode.OK Then
                        Dim _ContentLenght As Integer = response.ContentLength
                        If _ContentLenght <= 0 Then Throw New Exception("Impossible d'obtenir la taille du fichier.")
                        Using stream As Stream = response.GetResponseStream()
                            Using fs As New FileStream(_DirectoryPath, FileMode.Create, FileAccess.Write, FileShare.Write)
                                Dim buffer As Byte() = New Byte(2048 - 1) {}
                                Dim _TotalBytesReceived As Integer = 0
                                Dim readsize As Integer = stream.Read(buffer, 0, buffer.Length)
                                While readsize > 0
                                    fs.Write(buffer, 0, readsize)
                                    _TotalBytesReceived += readsize
                                    OnDownloadProgress(Me, New DownloadProgressArgs(_TotalBytesReceived, _ContentLenght))
                                    Return
                                End While
                            End Using
                        End Using
                    Else
                        Throw New Exception("Échec de l'état de retour du serveur, StatusCode: " & response.StatusCode)
                    End If
                End Using
                OnDownloadCompleted(Me, New DownloadCompletedArgs(False))
            Catch ex As Exception
                OnDownloadCompleted(Me, New DownloadCompletedArgs(True))
            End Try
        End Sub
    End Class
     
    Public Class DownloadCompletedArgs : Inherits System.EventArgs
     
        Private _Error As Boolean
     
        Public Sub New(ByVal Err As Boolean)
            _Error = Err
        End Sub
     
        Public ReadOnly Property [Error] As Boolean
            Get
                Return _Error
            End Get
        End Property
    End Class
     
    Public Class DownloadProgressArgs : Inherits System.EventArgs
     
        Private _BytesReceived As Integer
        Private _TotalBytesReceived As Integer
     
        Public Sub New(ByVal BytesReceived As Integer, ByVal TotalBytesReceived As Integer)
            _BytesReceived = BytesReceived
            _TotalBytesReceived = TotalBytesReceived
        End Sub
     
        Public ReadOnly Property BytesReceived As Integer
            Get
                Return _BytesReceived
            End Get
        End Property
     
        Public ReadOnly Property TotalBytesReceived As Integer
            Get
                Return _TotalBytesReceived
            End Get
        End Property
     
        Public ReadOnly Property ProgressPercentage As Integer
            Get
                If _TotalBytesReceived > 0 Then
                    Return Math.Ceiling((_BytesReceived / _TotalBytesReceived) * 100)
                Else
                    Return 0
                End If
            End Get
        End Property
    End Class
    pouvez vous m'aider pourquoi dans listview1 ça bloque à 1 % voir image?

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 586
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 586
    Par défaut
    je pense qu'il nous manque la fonction DownloadProgressedChanged puisque c'est dans elle que tu dois gérer l'affichage sauf erreur

  3. #3
    Membre éprouvé
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    323
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 323
    Par défaut
    bonsoir umfred, merci de ta réponse mais j'ai abandonné pour l'instant. je fait résoudre un peu plus tard le problème.

  4. #4
    Membre Expert
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 586
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 586
    Par défaut
    ça n'empêche pas que tu puisses nous donner le code de cette fonction.... on ne sait jamais...

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 27/06/2007, 12h45
  2. Réponses: 7
    Dernier message: 04/06/2007, 13h31
  3. la division par zero pour effectuer un pourcentage dans une requete
    Par VIRGINIE87 dans le forum Requêtes et SQL.
    Réponses: 12
    Dernier message: 24/05/2007, 22h44
  4. Calcul pourcentage dans un sous formulaire
    Par kriskiller dans le forum Access
    Réponses: 9
    Dernier message: 11/07/2006, 09h45
  5. [CR8.5] Pourcentage dans tableau ?
    Par Etienne51 dans le forum SAP Crystal Reports
    Réponses: 4
    Dernier message: 20/08/2004, 14h00

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