0

我目前正在处理应用程序从文件夹中获取文件并到达每个图像以获取条形码的项目。当它读取条形码时,它会将所有非条形码文件推送到数组中,并且该文件数组将与目的地中具有唯一名称的多页单 tiff 图像合并。我所做的一切和它的工作,但我想使用线程让它快速。我有这样的功能 -

  1. 读取图像文件直到达到条形码。
  2. 在目标文件夹中创建一个唯一的名称
  3. 制作多页单tiff图像
  4. 将其保存在目标文件夹中。

阅读条形码我使用简单的条形码阅读器,我得到图像有条形码或没有条形码。我在 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();
     }
4

1 回答 1

0

试试这个逻辑

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Net;
using System.Collections;
using System.Threading;
namespace ConsoleApplication4
{


    static class Program
    {
        private static ManualResetEvent wh;
        private static int total;
        private static int done;
        private static void Main()
        {

            string[] myfiles = new string[] {"file1", "file2"};
            wh = new ManualResetEvent(false);
            total = myfiles.Length;
            foreach (string myfile in myfiles)
            {
                ThreadPool.QueueUserWorkItem(ProcessImageFile, myfile);
            }
            wh.WaitOne(Timeout.Infinite);

            //wohoo all files are process now, at faster rate;

        }

        private static void ProcessImageFile(object state)
        {
            string file = state as string;

            // process the file here

            Interlocked.Increment(ref done);

            if (done == total)
            {
                wh.Set();
            }

        }
    }

}
于 2012-12-29T03:48:51.517 回答