Search code examples
.netc#-4.0iobarcode

Generating 10000 matrix bar codes takes too much time


Problem

When generating 2d bar code matrices it takes 1 minute per 10000 files. How to generate 2d bar code matrices for big quantities in less time?

Below is my code executed when clicking button.

The library used to encode data is in thislink:

http://www.mediafire.com/file/ciadoloynverba7/library_used_for_datamatrix.txt

Code:

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 ");

When create 10000 it takes 1 minute, if I write 200000 in textbox1 it takes 20 minutes.

The code is working without any problems and gives me result that I need, but it is slow in generating data for big quantities, so what should I do to make generating bar codes faster? image to file generating


Solution

  • DataTable is not the ideal data structure for doing this, it is too slow. Try to load your data using a connected structure, like a data reader.

    also, you could try to balance this writing a multi-threading code that code processes a few different loops at the same time.