C # Ionic.Zip Progressbar come sfondo lavoratore
Domanda
ho ricevuto il seguente codice:
string path = Environment.CurrentDirectory;
private void button1_Click(object sender, EventArgs e)
{
using (ZipFile zip = ZipFile.Read("Fringe.S03E07.HDTV.XviD-LOL.zip"))
{
zip.ExtractProgress += ExtractProgress;
foreach (ZipEntry file in zip)
{
file.Extract(path+"\\temp", ExtractExistingFileAction.OverwriteSilently);
}
}
}
public void ExtractProgress(object sender, ExtractProgressEventArgs e)
{
if (e.EventType == ZipProgressEventType.Extracting_EntryBytesWritten)
{
//bytes transfered of current file
label4.Text = e.BytesTransferred.ToString();
}
else if (e.EventType == ZipProgressEventType.Extracting_BeforeExtractEntry)
{
//filename of current extracted file
label2.Text = e.CurrentEntry.FileName;
}
}
quando clicco sul pulsante, il modulo si blocca. Voglio fare l'ExtractProgress come sfondo lavoratore, ma quando io non so come convertire la funzione alla funzione BackgroundWorker perché la funzione ExtractProgress richiedono ExtractProgressEventArgs e e la funzione backgroundworker_dowork richiedono DoWorkEventArgs e.
se qualcuno può aiutarmi a convertire o di darmi un'altra soluzione che sarà fantastico!
Soluzione
Semplice: basta mettere tutti il codice in button1_Click
in un metodo, e hanno button1_Click
percorso che metodo in una BackgroundWorker
. Provare e vedere come va a finire.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow