当生成10000矩阵条形码时,如何使生成花费几秒钟需要花费太多时间 [英] When generate 10000 matrix bar code it take too much time how to make generating take seconds

查看:153
本文介绍了当生成10000矩阵条形码时,如何使生成花费几秒钟需要花费太多时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



生成矩阵2d条形码时,每10000个文件生成矩阵条形码生成



需要1分钟。



这样如何在更短的时间内生成矩阵条形码2d秒。



我的代码如下按钮生成:



Problem

When generating matrix 2d bar code it take per 10000 files matrix bar code generating

it take 1 minute .

so that how to generating matrix bar code 2d in less time as seconds .

my code as below under button generating :

Class1 CLS = new Class1();
                DataTable dt = CLS.ShowalldataSerial(textBox4.Text);

                for (int i = 0; i <= Convert.ToInt32(textBox1.Text); i++)
                {
                    Serial = SRL.Rnd().ToString();
                    txt = "UserID" + dt.Rows[0][0] + "FirmName" + dt.Rows[0][1] + "OrderNo" + dt.Rows[0][2] + "BtachNo" + dt.Rows[0][3] + "Quantity" + dt.Rows[0][4] + "ProductName" + dt.Rows[0][5] + "SerialNo" + Serial;

                    dm.DM(txt, Color.FromName(comboBox1.SelectedItem.ToString()), Color.White).Save(root + "\\" + Serial + ".emf", System.Drawing.Imaging.ImageFormat.Emf);

                }
                MessageBox.Show("Records generated success ");







在textbox1中创建10000时如果我写的话需要一分钟



200000 in textbox1需要20分钟



代码工作没有任何问题,并给我结果我需要



但它会大量生成数据矩阵



这样我就可以非常快速地生成矩阵条形码。



我的尝试:






when create 10000 in textbox1 it take minute if i write

200000 in textbox1 it take 20 minutes

Code working without any problem and give me result what i need

but it slowly generating data matrix per big quantities

so that what i do to make generating matrix bar code very fast .

What I have tried:

when generate 10000 matrix bar code it take too much time How to make generating take seconds

推荐答案

我建​​议您有多个线程来编写这些条形码 - 请参阅异步编程 [ ^ ]



顺便说一下,做你自己和其他人赞成并停止使用自动生成的对象名称 Class1 textBox1 textBox4 等等。他们现在可能对你有意义,但是当你必须回到这个代码时,它们在6个月内对你毫无意义。目前它只是让你看起来非常不专业。
I suggest that you have multiple threads writing these barcodes - see Asynchronous Programming[^]

As an aside, do yourself and everybody else a favour and stop using the automatically generated names for objects Class1, textBox1, textBox4 etc etc. They might mean something to you now but they will be meaningless to you in 6 months time when you have to come back to this code. At the moment it just makes you look very unprofessional.


在这一行:

In this line:
txt = "UserID" + dt.Rows[0][0] + "FirmName" + dt.Rows[0][1] + "OrderNo" + dt.Rows[0][2] + "BtachNo" + dt.Rows[0][3] + "Quantity" + dt.Rows[0][4] + "ProductName" + dt.Rows[0][5] + "SerialNo" + Serial;



,循环中的一个重要部分是常量:


, a big part is constant in the loop:

"UserID" + dt.Rows[0][0] + "FirmName" + dt.Rows[0][1] + "OrderNo" + dt.Rows[0][2] + "BtachNo" + dt.Rows[0][3] + "Quantity" + dt.Rows[0][4] + "ProductName" + dt.Rows[0][5] + "SerialNo"



通过将常量部分移动到循环外部,应该节省一些时间。


By moving the constant part outside of the loop, you should save some time.

Quote:

root +\\+ Serial +。emf

root + "\\" + Serial + ".emf"



您是否将每个条形码保存在硬盘根目录中的单独文件中?



优化本身就是一项工作为了有效率,我们必须知道你所做的细节,以便评估提高效率的其他可能性。


Are you saving each bar code in a separate file in root of hard drive ?

Optimization is a job by itself, and to be efficient, one must know the details of what you do in order to evaluate the other possibilities to get more efficient.


正如已经建议的那样,将任何常量数据移出循环并且避免在循环中使用本地和临时变量(特别是那些使用动态内存分配的字符串):

As already suggested move any constant data out of the loop and avoid using local and temporary variables inside the loop (especially those using dynamic memory allocation like strings):
int items = Convert.ToInt32(textBox1.Text);
string txtBase = "UserID" + dt.Rows[0][0] + "FirmName" + dt.Rows[0][1] + "OrderNo" + dt.Rows[0][2] + "BtachNo" + dt.Rows[0][3] + "Quantity" + dt.Rows[0][4] + "ProductName" + dt.Rows[0][5] + "SerialNo";
Color color = Color.FromName(comboBox1.SelectedItem.ToString());
string filePath = root + "\\";
string fileName;
// Note: This will create items + 1 labels!
for (int i = 0; i <= items; i++)
{
    Serial = SRL.Rnd().ToString();
    txt = txtBase + Serial;
    fileName = filePath + Serial + ".emf";
    dm.DM(txt, color, Color.White).Save(fileName, System.Drawing.Imaging.ImageFormat.Emf);
}

这应该减少整体运行时间。但最耗时的操作是文件创建无法加速,可能是 DM()调用。



在您的评论中,您提到生成的文件将在稍后打印。我想打印比生成文件花费更多时间。如果可能,您可能会尝试从循环内打印标签。然后你不需要将它们写入文件。

This should reduce the overall run time. But the most time consuming operation is the file creation which can't be speed up and maybe the DM() call.

In your comments you mentioned that the generated files will be printed later. I guess that printing took more time than generating the files. If possible you might try to print the labels from within the loop. Then you don't need to write them to files.


这篇关于当生成10000矩阵条形码时,如何使生成花费几秒钟需要花费太多时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆