c# - 并行压缩文件夹,c#中的最佳解决方案
问题描述
我需要在不同的档案中同时压缩更多的文件夹以更快地进行。我尝试使用一个主要的后台工作人员,并从这里我做了一个 for 循环来为每个文件夹启动其他后台工作人员。我注意到后台工作人员同时启动但不能一起工作什么是做并行存档的最佳方法?你建议什么?创建存档我使用 zipforge 库
DoWork of the main backgroundworker
if (Directory.Exists(destination))
{
if (MessageBox.Show("", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
{
goto EXIT_UTENTE;
}
else
{
bool finish = false;
int j = 1;
string dest_appoggio = destination;
do
{
dest_appoggio = destination + "_" + j;
if (Directory.Exists(dest_appoggio))
{
j++;
}
else
{
destination = dest_appoggio;
dataprogressiva = data + "_" + j;
finish = true;
}
}
while (finish == false);
}
}
destinationdefault = destination;
var row_list1 = GetDataGridRows(dgwRobot);
int riga = -1;
foreach (DataGridRow single_row1 in row_list1)
{
bool rowselected = false;
single_row1.Dispatcher.Invoke(new Action(() => { rowselected = single_row1.IsSelected; }));
if (rowselected == true)
{
riga = single_row1.GetIndex();
var robotProcessed = false;
while (!robotProcessed)
{
for (var threadNum = 0; threadNum < MaxBackupContemporanei; threadNum++)
{
if (!threadArray[threadNum].IsBusy)
{
threadArray[threadNum].RunWorkerAsync(riga);
robotProcessed = true;
break;
}
}
}
}
Thread.Sleep(500);
}
bool bwTerminati = false;
while (!bwTerminati)
{
for (var threadNum = 0; threadNum < MaxBackupContemporanei; threadNum++)
{
if (threadArray[threadNum].IsBusy)
{
bwTerminati = false;
threadNum = MaxBackupContemporanei;
}
else
{
bwTerminati = true;
}
}
}
解决方案
推荐阅读
- python - python中多线程读写json文件的并发性
- codeigniter - 在 codeignter 模型中从两列到两个日期中选择
- php - 如何将大量 HTML 表单的表值发布到 PHP 数组?
- c++ - 如何计算和存储向量中目录中的文件
- python - KeyError: ((1, 1, 1280), '|u1') while using PIL's Image.fromarray - PIL
- protocol-buffers - 如何在 ProtoBuf (gRPC) - Proto3 语法中添加消息类型作为对象?
- typescript - 输入'HTMLCollectionOf
' 必须有一个返回迭代器的 '[Symbol.iterator]()' 方法 - spring - 从所有其他微服务获取当前经过身份验证的用户
- sql - 查询中的多个 Drop table 语句失败
- google-apps-script - 活动工作表中的 getUi