Pregunta

Tengo el siguiente código:

        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;
        }
    }

cuando hago clic en el botón, la forma queda bloqueado. Quiero hacer el ExtractProgress como trabajador de fondo, pero cuando no saben cómo convertir la función a la función BackgroundWorker porque la función ExtractProgress requiere ExtractProgressEventArgs la función backgroundworker_dowork correo electrónico y requieren DoWorkEventArgs.

si alguien me puede ayudar a convertir o darme otra solución que será muy bueno!

¿Fue útil?

Solución

simple: sólo hay que poner todos en el código button1_Click en un método, y tienen button1_Click ejecución de ese método en un BackgroundWorker. Probarlo y ver cómo funciona.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top