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 :

Progressbar et bloquage du logciel


Sujet :

VB.NET

  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Septembre 2009
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2009
    Messages : 35
    Par défaut Progressbar et bloquage du logciel
    boujours à tous et à toutes,
    Voila j'ai fait un petit programme qui ce lance par le biais d'une planification windows jusque l'a pas de soucis.
    Mon programme doit copier un fichier de 60,5go d'un DD externe à un autre DD externe (ce programme copie un fichier virtual disk un .vhd).
    mais voilà, premier probleme, je sais pas l'avancement de la copie et de deux le programme ce bloque (mais la copie à l'air de ce faire).
    donc j'aimerais savoir, si il y a un moyen deja de débloquer le programme en question (ne plus avoir le programme ne repond plus car si on le ferme la copie est bonne à refaire et si on met une progressbar la progressbar en question ne marchera pas) et comment faire pour utiliser la progressbar lors d'une copie

    je mets mon programme:


    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
    Public Class Form1
     
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
            'on cherche le fichier sur un disque E, F, G, et H
     
            'teste l'exitance du fichier a copier sur le E
            If System.IO.File.Exists("e:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("f:\hhh.txt") Then
                    File.Copy("e:\DDexterne.vhd", "f:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("g:\hhh.txt") Then
                    File.Copy("e:\DDexterne.vhd", "g:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("h:\hhh.txt") Then
                    File.Copy("e:\DDexterne.vhd", "h:\copyDDexterne.vhd")
     
                End If
     
                'teste l'exitance du fichier a copier sur le F
            ElseIf System.IO.File.Exists("F:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("e:\hhh.txt") Then
                    File.Copy("f:\DDexterne.vhd", "e:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("g:\hhh.txt") Then
                    File.Copy("f:\DDexterne.vhd", "g:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("h:\hhh.txt") Then
                    File.Copy("f:\DDexterne.vhd", "h:\copyDDexterne.vhd")
                End If
     
                'teste l'exitance du fichier a copier sur le g
            ElseIf System.IO.File.Exists("g:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("e:\hhh.txt") Then
                    File.Copy("g:\DDexterne.vhd", "e:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("f:\hhh.txt") Then
                    File.Copy("g:\DDexterne.vhd", "f:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("h:\hhh.txt") Then
                    File.Copy("g:\DDexterne.vhd", "h:\copyDDexterne.vhd")
                End If
     
                'teste l'exitance du fichier a copier sur le h
            ElseIf System.IO.File.Exists("h:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("e:\hhh.txt") Then
                    File.Copy("h:\DDexterne.vhd", "e:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("g:\hhh.txt") Then
                    File.Copy("h:\DDexterne.vhd", "g:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("f:\hhh.txt") Then
                    File.Copy("h:\DDexterne.vhd", "f:\copyDDexterne.vhd")
                End If
     
                End
     
     
            End If
        End Sub
     
     
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     
            If Label1.ForeColor = Color.Black Then
                Label1.ForeColor = Label1.BackColor
            Else
                Label1.ForeColor = Color.Black' met ici ta couleur habituelle d'écriture
            End If
     
        End Sub
     
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
        End Sub
     
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            End
        End Sub
    End Class

  2. #2
    Membre Expert Avatar de meziantou
    Homme Profil pro
    autre
    Inscrit en
    Avril 2010
    Messages
    1 223
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : autre
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 1 223
    Par défaut
    Utilise un BackGroundWorker. Ca permet d'exécuter des taches lourdes (comme ta copie) en parallèle et aussi de mettre à jour ton UI.
    Pour connaître l'avancement je pense qu'il faut réécrire la fonction de copie ce n'est pas très dur, un streamreader et un streamwriter. Tu lis un block, tu l'écrit et tu mets à jour ta ProgressBar.

  3. #3
    Membre averti
    Homme Profil pro
    Inscrit en
    Septembre 2009
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2009
    Messages : 35
    Par défaut
    merci à toi meziantou,
    J'ai pu avancer, mais pour la progressbar c'est le calme plat.
    Je sais pas du tout me servir de la progressbar. (En meme temps, je connaissais pas backgroundworker).


    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
    Public Class Form1
     
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
     
                Label1.Text = "Traitement en cours..."
                BackgroundWorker1.RunWorkerAsync()
                BackgroundWorker1.WorkerReportsProgress = True
     
         End Sub
     
     
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     
        If Label1.ForeColor = Color.Black Then
            Label1.ForeColor = Label1.BackColor
        Else
            Label1.ForeColor = Color.Black ' met ici ta couleur habituelle d'écriture
        End If
     
        End Sub
     
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
        End Sub
     
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            End
        End Sub
     
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
     
            'on cherche le fichier sur un disque E, F, G, et H
     
           'teste l'exitance du fichier a copier sur le E
            If System.IO.File.Exists("e:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("f:\hhh.txt") Then
                    File.Copy("e:\DDexterne.vhd", "f:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("g:\hhh.txt") Then
                    File.Copy("e:\DDexterne.vhd", "g:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("h:\hhh.txt") Then
                    File.Copy("e:\DDexterne.vhd", "h:\copyDDexterne.vhd")
     
                End If
     
                'teste l'exitance du fichier a copier sur le F
            ElseIf System.IO.File.Exists("F:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("e:\hhh.txt") Then
                    File.Copy("f:\DDexterne.vhd", "e:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("g:\hhh.txt") Then
                    File.Copy("f:\DDexterne.vhd", "g:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("h:\hhh.txt") Then
                    File.Copy("f:\DDexterne.vhd", "h:\copyDDexterne.vhd")
                End If
     
                'teste l'exitance du fichier a copier sur le g
            ElseIf System.IO.File.Exists("g:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("e:\hhh.txt") Then
                    File.Copy("g:\DDexterne.vhd", "e:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("f:\hhh.txt") Then
                    File.Copy("g:\DDexterne.vhd", "f:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("h:\hhh.txt") Then
                    File.Copy("g:\DDexterne.vhd", "h:\copyDDexterne.vhd")
                End If
     
                'teste l'exitance du fichier a copier sur le h
            ElseIf System.IO.File.Exists("h:\DDexterne.vhd") Then
     
                If System.IO.File.Exists("e:\hhh.txt") Then
                    File.Copy("h:\DDexterne.vhd", "e:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("g:\hhh.txt") Then
                    File.Copy("h:\DDexterne.vhd", "g:\copyDDexterne.vhd")
                ElseIf System.IO.File.Exists("f:\hhh.txt") Then
                    File.Copy("h:\DDexterne.vhd", "f:\copyDDexterne.vhd")
                End If
     
                End
     
     
            End If
        End Sub
    End Class
    comment je dois m'y prendre pour faire une progressbar ?

  4. #4
    Membre Expert Avatar de meziantou
    Homme Profil pro
    autre
    Inscrit en
    Avril 2010
    Messages
    1 223
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : autre
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 1 223
    Par défaut
    Je sais pas du tout me servir de la progressbar
    Ce n'est pas le plus dur. Il y a 3 propriétés importantes : MinValue, MaxValue et Value. En plus elles sont explicites donc ils n'y a pas besoin de faire une description.

    Le problème vient du fait que File.Copy ne donne aucune information concernant l'avancement de la copy. Il faut donc implémenter toi même celle-ci. Ce n'est pas très dur.

  5. #5
    Membre actif

    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 51
    Par défaut
    Pour ton background worker, tu dois déclarer et configurer ton objet d'une part, et d'autre part, faire un traitement dans l'évènement DoWork. Si tu veux mettre à jour ton interface (ta progressBar) tu devrais utiliser l'évènement ReportProgress du background worker. Pour finir, une fois le traitement terminé, tu pourras voir les résultats dans l'évènement RunWorkerCompleted.

    Bonne chance!

Discussions similaires

  1. [MFC] afficher une ProgressBar dans une barre d'etat
    Par guillaume21 dans le forum MFC
    Réponses: 5
    Dernier message: 30/03/2007, 11h16
  2. Problème : bloquage d'un pipe
    Par Nicaisse dans le forum POSIX
    Réponses: 10
    Dernier message: 24/07/2003, 11h06
  3. comment programmer une progressbar
    Par Choucas dans le forum Paradox
    Réponses: 3
    Dernier message: 13/11/2002, 11h07
  4. ProgressBar avec plusieurs procédures
    Par elifqaoui dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 08/09/2002, 18h03
  5. Couleur de ProgressBar
    Par benj63 dans le forum C++Builder
    Réponses: 7
    Dernier message: 04/07/2002, 17h33

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