【发布时间】:2012-12-14 05:35:09
【问题描述】:
我目前正在处理应用程序从文件夹中获取文件并到达每个图像以获取条形码的项目。当它读取条形码时,它将所有非条形码文件推送到数组中,并且该文件数组将与目标中具有唯一名称的多页单 tiff 图像合并。 我所做的一切和它的工作,但我想使用线程让它快速。 我有类似的功能 -
- 读取图像文件直到到达条形码。
- 在目标文件夹中创建一个唯一的名称
- 制作多页单tiff图像
- 将其保存在目标文件夹中。
要读取条码,我使用简单的条码阅读器,我在其中得到图像有条码或没有条码。其余的我正在处理 foreach 循环中的数组。一些代码在这里
foreach (string path in filenames_1)
{
Image bmp = Bitmap.FromFile(path);
Bitmap bn = (Bitmap)bmp;
readimage(bn);
if (s == 1) //If it is Bookmarked Content Found Then s=1 else its s=0
{
if (z == 0) // i used z coz in my process first file in directory is barcode image so first time have to skip it so i set z=1 at begining and second time it become 0 and process continues
{
j = 3; continue;
MakeUnique("c:\\sachin.tiff");
ConvertToMultiPageTiff(fileNames, fnamem);
fileNames.Clear();
}
fileNames.Add(path);
j = 1;
if (z == 0)
{
j = 3;
}
else
{
}
}
else
{
if (j == 1) // j==1 means its regular tiff file wher i make them add to string array
{
fileNames.Add(path); // string array with files to be made multiple tiff image become single mulipage tiff image
j = 1;
z = 0;
}
if (j == 3)
{
z = 1;
j = 1;
fileNames.Add(path);
MakeUnique("c:\\sachin.tiff");
ConvertToMultiPageTiff(fileNames, fnamem); // this function converts all the added files in filearray of single tiff image to multiple page single tiff image
fileNames.Clear();
}
else
{
}
}
}
}
MakeUnique("c:\\sachin.tiff");
ConvertToMultiPageTiff(fileNames, fnamem);
fileNames.Clear();
}
【问题讨论】:
-
很有可能这将是 IO 受限操作......因为随着 HD 竞争的增加,“多线程”实际上会减慢速度。 WTF 是
s、j和z,你能在一周内记住吗? -
如果您“按顺序”执行此操作,则使用多个线程没有任何好处。多线程的全部目的是同时做多件事情。 “我想通过使用多个线程来更快地完成它,但我想一次只运行一个”是无稽之谈;如果您一次运行一个线程,则不涉及“更快”。还是一次一个。
标签: c#