相关疑难解决方法(0)

进度条不适用于zipfile?当程序似乎挂起时如何提供反馈

我对C#和编码很新,所以其中一些可能是错误的方式.我编写的程序按预期工作并压缩文件,但如果源代码很大,程序会出现(对Windows)挂起.我觉得我应该使用a Thread但我不确定这会有所帮助.

我会使用进度条,但是用于zipfile的'new'(.net 4.5)库System.IO.Compression,替换后 Ionic.Zip.ZipFile没有报告进度的方法?有没有解决的办法?我应该使用Thread吗?还是DoWork

问题是用户和系统没有得到关于程序正在做什么的反馈.

我不确定我是以正确的方式提出这个问题.下面是正在运行的代码,但同样会出现挂起系统的问题.

    private void beginBackup_Click(object sender, EventArgs e)
    {
        try
        {
            long timeTicks = DateTime.Now.Ticks;
            string zipName = "bak" + timeTicks + ".zip";
            MessageBox.Show("This Will take a bit, there is no status bar :(");
            ZipFile.CreateFromDirectory(Properties.Settings.Default.source,
                  Properties.Settings.Default.destination + "\\" + zipName);
            MessageBox.Show("Done!");
            this.Close();
        }
        catch (IOException err)
        {
            MessageBox.Show("Something went wrong" + System.Environment.NewLine
                + "IOException source: {0}", err.Source);
        }
    }
Run Code Online (Sandbox Code Playgroud)

重要的是:

        `ZipFile.CreateFromDirectory(Properties.Settings.Default.source,
              Properties.Settings.Default.destination + "\\" + zipName);`
Run Code Online (Sandbox Code Playgroud)

编辑 …

c# multithreading zipfile

2
推荐指数
1
解决办法
4454
查看次数

标签 统计

c# ×1

multithreading ×1

zipfile ×1