[英]C# Ionic.Zip progressbar as background worker
I got the following code: 我得到以下代码:
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;
}
}
when I click on the button, the form get stuck. 当我单击按钮时,表单卡住了。 I want to make the ExtractProgress as background worker but when I dont know how to convert the function to backgroundworker function because the ExtractProgress function require ExtractProgressEventArgs e and the backgroundworker_dowork function require DoWorkEventArgs e.
我想将ExtractProgress用作后台工作者,但是当我不知道如何将函数转换为backgroundworker函数时,因为ExtractProgress函数需要ExtractProgressEventArgs e,而backgroundworker_dowork函数需要DoWorkEventArgs e。
if someone can help me to convert it or to give me another solution it will be great! 如果有人可以帮助我转换它或给我另一个解决方案,那将是很棒的!
Simple: just put all the code in button1_Click
into a method, and have button1_Click
run that method in a BackgroundWorker
. 简单:只需将
button1_Click
所有代码放入方法中,然后让button1_Click
在BackgroundWorker
运行该方法。 Try it and see how it works out. 尝试一下,看看效果如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.