I have 3 textboxes. 1st and 2nd textboxes contain approximately 40.000 to 80.000 lines of data. Each line has 6-7 characters maximum. Last checkbox has 800-1000 lines of data. These lines also has 6-7 characters. To save all these data in a single text file, I first add a time tag at beginning of each line, after a tab first textbox line written, and then second tbox, and third tbox, and then a new line. It goes on like that.
I use 3 checkboxes to understand which textboxes user wants to save. After save button clicked, this loop below starts. But it takes so long. Even user selects to save only first textbox, which means, let's say 50.000 lines, it takes almost a minute!
I tried methods like writing in a string, with a StringBuilder, with do-while loops, etc. but can't get a significant effect. I searched on internet and forum about different methods but couldn't find a way.
Is there any effective way to make it work faster?
For i = 0 To linesCount - 1
textStr.Append(timeCount & vbTab)
If (cbSaveOutput.Checked And Not tbOutput.Text = "") Then textStr.Append(tbOutput.Lines(i) & vbTab)
If (cbSaveForce.Checked And Not tbForce.Text = "") Then textStr.Append(tbForce.Lines(i) & vbTab)
If (cbSaveCrop.Checked And Not tbCroppedData.Text = "" And i < tbCroppedData.Lines.Length) Then textStr.Append(tbCroppedData.Lines(i))
textStr.Append(Environment.NewLine)
timeCount = Math.Round(timeCount + (1 / tbSampleRate.Text), 6)
ProgressBar1.Increment(1)
Next
question from:
https://stackoverflow.com/questions/65626488/vb-net-for-loop-takes-so-long 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…