Actually, problem is not in adding files into a zip which contains a lot of items (in your case it should took less then 1s), but it is in archive shrinking.
You use ArchiveActionOnExistingFile.OverwriteOlder
which can cause the files with the same name are deleted from archive at first, then the more recent file is added into archive. This makes a hole (unused space) within the archive. If the archive has 2800 * 64kb files, it means it is approx. 180MB file.
When using ZipArchive.Add
method, the hole is automatically "removed" (archive is shrinked) which can take approx. 1 min.
You can choose between the two: Either you create "large" archives quickly or "small" archives slowly.
To disable automatic archive shrinking use this:
// add file into archive without shrinking
using (ZipArchive zip = new ZipArchive(ZipPath))
{
// disable auto-shrink
zip.SaveMode = ArchiveSaveMode.Delayed;
// add required file
zip.Add(Path.Combine(KameraPath, _filename), null, 0, 0, ActionOnExistingFiles.OverwriteOlder);
// save archive and skip shrinking
zip.Save(ArchiveSaveAction.None);
}
When you are done or when you decide to shrink the archive (e.g. it exceeds 1GB size on disk), you can invoke Shrink like this (but please note, it can take approx. 1 min):
// shrink the archive
using (ZipArchive zip = new ZipArchive(ZipPath))
{
zip.Save(ArchiveSaveAction.Shrink);
}