Click here to Skip to main content
15,888,015 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
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 :

C#
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 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
Posted
Updated 7-May-17 23:04pm
Comments
Patrice T 7-May-17 9:32am    
And the user absolutely need all 200000 bar codes instantly.
And they are all used.
And the screen is large enough to display all 200000 bar code at once.
CHill60 7-May-17 9:47am    
Buy a machine with faster I/O speeds.
This code is slightly faster than string concatenation
txt = String.Format("UserID{0}FirmName{1}OrderNo{2}BtachNo{3}Quantity{4}ProductName{5}SerialNo{6}",
                                dt.Rows[0][0], dt.Rows[0][1], dt.Rows[0][2], dt.Rows[0][3], dt.Rows[0][4], dt.Rows[0][5], Serial);

But as @ppolymorphe has hinted, who is going to need 200,000 barcodes in seconds?
ahmed_sa 7-May-17 10:11am    
I asking if there are any thing can do my generating faster
ahmed_sa 7-May-17 10:11am    
this is not for user this is for pharmaceutical company need to print barcode on pakages of medicin
Patrice T 7-May-17 12:54pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

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.
 
Share this answer
 
In this line:
C#
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:
C#
"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"

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.
 
Share this answer
 
Comments
ahmed_sa 7-May-17 18:36pm    
so that please if possible how to write .save function
root + "\\" + Serial + ".emf" for more speed and performance
please any one can answer for me
Patrice T 7-May-17 20:37pm    
Would need to know the what and the why of the function.
ahmed_sa 8-May-17 4:24am    
are there are any way to create files data matrix barcode without using save
if there are please tell me
because i dont know
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):
C#
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);
}
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900