Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [VB.NET] Background Worker

    Stò facendo un programma che utilizza un background worker per poter fare un download da ftp in asincrono. Dato che la progress bar del vb non mi piace per niente, mi sono creato io personalmente una progress bar grafica con delle pictureBox. La domanda ora è: come faccio a modificare le proprietà della pictureBox tramite il background worker? vi posto la parte di codice e il log errore:

    Private Sub bgwConnect_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwConnect.DoWork
    Dim t As New Threading.Thread(AddressOf DownloadDB) 'Dowload file from FTP
    Dim t2 As New Threading.Thread(AddressOf DropAdvancing) 'Avanzamento progressbar
    t.Start()
    t2.Start()
    While t.IsAlive
    'Stuff
    End While
    t2.Abort()
    End Sub

    Public Sub DropAdvancing()
    Do
    pct1.Visible = False
    pct2.Visible = False
    pct3.Visible = False
    System.Threading.Thread.Sleep(100)
    pct1.Visible = True
    System.Threading.Thread.Sleep(100)
    pct2.Visible = True
    System.Threading.Thread.Sleep(100)
    pct3.Visible = True
    Loop
    End Sub

    log errore:

    Cross-thread operation not valid: Control 'pct1' accessed from a thread other than the thread it was created on.


    Grazie mille!

  2. #2
    Utente di HTML.it L'avatar di cassano
    Registrato dal
    Aug 2004
    Messaggi
    3,002
    Scusa perche usi il BW e poi al suo interno usi altri thread ?.

    Non ti conviene gestire tutto col BW e usare il metodo progresschange per modificare la tua progressbar ?.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.