ProgressBar funzt während eines Vorgangs net :/

  • VB.NET

Es gibt 14 Antworten in diesem Thema. Der letzte Beitrag () ist von Mr.Blade.

    ProgressBar funzt während eines Vorgangs net :/

    Hi!
    Hab ein kleines Problem, und zwar folgendes:
    (Hab mal grad die Codes hier eingefügr::)
    /// Der Button

    VB.NET-Quellcode

    1.   Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
    2.   ProgressBar1.Visible = True
    3.   ProgressBar1.Value = 10
    4.   System.Threading.Thread.Sleep(20)
    5.   Log.ListBox1.Items.Clear()
    6.   ProgressBar1.Value = 20
    7.   System.Threading.Thread.Sleep(20)
    8.   Log.TextBox1.Clear()
    9.   ProgressBar1.Value = 30
    10.   System.Threading.Thread.Sleep(20)
    11.   Dim counter As _
    12. System.Collections.ObjectModel.ReadOnlyCollection(Of String)
    13.   counter = My.Computer.FileSystem.GetFiles( _
    14. ("C:\TEST\"), _
    15. FileIO.SearchOption.SearchAllSubDirectories)
    16.   ProgressBar1.Value = 60
    17.   System.Threading.Thread.Sleep(20)
    18.   Log.TextBox1.Text = (CUInt(counter.Count) & (" Gefundene Dateien"))
    19.   ProgressBar1.Value = 70
    20.   System.Threading.Thread.Sleep(20)
    21.   For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
    22. ("C:\TEST\"), _
    23. FileIO.SearchOption.SearchAllSubDirectories, "*.*")
    24.   ProgressBar1.Value = 80
    25.   System.Threading.Thread.Sleep(20)
    26.   Log.ListBox1.Items.Add(foundFile)
    27.   ProgressBar1.Value = 90
    28.   System.Threading.Thread.Sleep(20)
    29.   ProgressBar1.Value = 90
    30.   System.Threading.Thread.Sleep(20)
    31.   ProgressBar1.Visible = False
    32.   Next
    33.   CopyWithProgress()
    34.   Application.DoEvents()
    35.   Log.ShowDialog()
    36.   End Sub

    /// ProgressBar

    VB.NET-Quellcode

    1.   Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
    2.   ' Display the ProgressBar control.
    3.   ProgressBar1.Visible = True
    4.   Application.DoEvents()
    5.   ' Set Minimum to 1 to represent the first file being copied.
    6.   ProgressBar1.Minimum = 1
    7.   Application.DoEvents()
    8.   ' Set Maximum to the total number of files to copy.
    9.   ProgressBar1.Maximum = ("C:\WINDOWS\Temp\").Length
    10.   Application.DoEvents()
    11.   ' Set the initial value of the ProgressBar.
    12.   ProgressBar1.Value = 1
    13.   Application.DoEvents()
    14.   ' Set the Step property to a value of 1 to represent each file being copied.
    15.   ProgressBar1.Step = 1
    16.   Application.DoEvents()
    17.   ' Loop through all files to copy.
    18.   Dim x As Integer
    19.   Application.DoEvents()
    20.   For x = 1 To filenames.Length - 1
    21.   Application.DoEvents()
    22.   ' Copy the file and increment the ProgressBar if successful.
    23.   Next x
    24.   End Sub

    -------------------------------------------------
    Irgendwie funktioniert der Progessbar nicht (Der CopyWithProgessBar)
    ------
    Wie man feststellen kann\sollte :D werden in einem bestimmten Verzeichniss, alle Dateien ermittelt, die dann in einem anderen Fenster (Log) wiedergegeben werden.
    1. ProgressBar ist für die Vorbereitung
    2. ProgressBar ist für den Ermittlungsvorgang, der im Hauptfenster angezeigt werden sollte, aber das funktioniert irgendwie nicht.
    ------
    Weiß jemand Rat ???
    Mfg.
    Wenn du fähig bist so eine Code zu schreiben, muß du auch fähig sein die Prozeduren/Funktionen mit Parameter richtig aufrufen ! Fange zuerst mit was einfacheres an bevor du was komplexes schreibst ! Damit ist der Thread für mich CLOSING ! :thumbsup:
    Für mich ist das nicht schwer, ob du die Code geschrieben hast oder irgend- jemand anderer, das interessiert mich überhaupt nicht ! ;)

    Schau dir mal genau die Funktion an:

    VB.NET-Quellcode

    1. Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
    2. ' Display the ProgressBar control.
    3. ProgressBar1.Visible = True
    4. Application.DoEvents()
    5. ' Set Minimum to 1 to represent the first file being copied.
    6. ProgressBar1.Minimum = 1
    7. Application.DoEvents()
    8. ' Set Maximum to the total number of files to copy.
    9. ProgressBar1.Maximum = ("C:\WINDOWS\Temp\").Length
    10. Application.DoEvents()
    11. ' Set the initial value of the ProgressBar.
    12. ProgressBar1.Value = 1
    13. Application.DoEvents()
    14. ' Set the Step property to a value of 1 to represent each file being copied.
    15. ProgressBar1.Step = 1
    16. Application.DoEvents()
    17. ' Loop through all files to copy.
    18. Dim x As Integer
    19. Application.DoEvents()
    20. For x = 1 To filenames.Length - 1
    21. Application.DoEvents()
    22. ' Copy the file and increment the ProgressBar if successful.
    23. Next x
    24. End Sub


    und wie du die Funktion aufrufst:

    VB.NET-Quellcode

    1. CopyWithProgress()


    ich denke, brauche weiter nicht mehr schreiben... :D :D :D ....

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Alex2000“ ()

    Ich glaub ich hab den Fehler gefunden ^^
    -

    VB.NET-Quellcode

    1. Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
    2.   ' Display the ProgressBar control.
    3.   ProgressBar1.Visible = True
    4.   Application.DoEvents()
    5.   ' Set Minimum to 1 to represent the first file being copied.
    6.   ProgressBar1.Minimum = 1
    7.   Application.DoEvents()
    8.   ' Set Maximum to the total number of files to copy.
    9.   ProgressBar1.Maximum = ("C:\WINDOWS\Temp\".Length)
    10.   Application.DoEvents()
    11.   ' Set the initial value of the ProgressBar.
    12.   ProgressBar1.Value = 1
    13.   Application.DoEvents()
    14.   ' Set the Step property to a value of 1 to represent each file being copied.
    15.   ProgressBar1.Step = 1
    16.   Application.DoEvents()
    17.   ' Loop through all files to copy.
    18.   Dim x As Integer
    19.   Application.DoEvents()
    20.   For x = 1 To ("C:\WINDOWS\TEMP".Length) - 1
    21.   Application.DoEvents()
    22.   ' Copy the file and increment the ProgressBar if successful.
    23.   Next x
    24.   End Sub
    ich hab deine Code noch ein mal angeschaut, und da mir was aufgefallen:

    VB.NET-Quellcode

    1. Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
    2. ' Display the ProgressBar control.
    3. ProgressBar1.Visible = True
    4. Application.DoEvents()
    5. ' Set Minimum to 1 to represent the first file being copied.
    6. ProgressBar1.Minimum = 1
    7. Application.DoEvents()
    8. ' Set Maximum to the total number of files to copy.
    9. ProgressBar1.Maximum = ("C:\WINDOWS\Temp\").Length
    10. Application.DoEvents()
    11. ' Set the initial value of the ProgressBar.
    12. ProgressBar1.Value = 1
    13. Application.DoEvents()
    14. ' Set the Step property to a value of 1 to represent each file being copied.
    15. ProgressBar1.Step = 1
    16. Application.DoEvents()
    17. ' Loop through all files to copy.
    18. Dim x As Integer
    19. Application.DoEvents()
    20. For x = 1 To filenames.Length - 1
    21. Application.DoEvents()
    22. ' Copy the file and increment the ProgressBar if successful.
    23. Next x


    id diese Code stehe nie irgend "ParamArray filenames " die Funktion übergibt die Anzahl zu kopierende Dateien.
    Die Dateien die du kopierem möchtest mus in eine Array rein schreiben. Dann die Funktion so aufrufen:

    VB.NET-Quellcode

    1. CopyWithProgress(DeineArray)