0
votes

I am using DotNetZip in a worker thread to extract files from a zip file. The thread function is listed below.

The bool var shouldStop should be used to stop the extracting by user if wanted. Now is the question: The tread works fine without "while (!shouldStop)" line. But if this line is there and even no other code changes shouldStop value, the thread extracts the 1st file in zip and generates error message saying the first file is already exists(the extract method can not overwrite an existing file). This means e is not moving to next element.

Could someone help me on this problem? Thanks!

Steven

    public void ExtractFiles()  // thread 
    {
        var options = new ReadOptions { StatusMessageWriter = System.Console.Out };

        using (ZipFile zip = ZipFile.Read(@folderName + @"\" + zipFileName, options))
        {
            foreach (ZipEntry e in zip.Entries)
            {
                // while (!shouldStop)
                {
                    e.Extract(@"d:\temp\temp1");
                }
            }
        }// using


    }// public void ReadFileList()
1

1 Answers

1
votes

You should not have a while loop inside the foreach loop. Just put an if statement inside the foreach loop and break if shouldStop is true.