몇 년 동안 기증자에서 수집 한 긴 전화 번호 목록을 별도의 지역 코드 파일로 구분하는 데 사용하는 간단한 간단한 스크립트가 있습니다.VB.NET 간단한 응용 프로그램이 여러 줄을로드하는 데 영원히 걸리는 이유
분명히, 당신은 거의 1 백만 라인을 가지고있을 때 그것은 한참 걸릴 것입니다. 그러나 제가 1,000을 넣으면 1 초도 걸리지 않습니다. 일단 내가 100 만분의 1을 넣으면 단 5 줄만 쓰려면 10 초가 걸립니다. 어떻게 될 수 있니?
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
Dim lines As String
lines = RichTextBox1.Lines.Count
Dim looper As String = 0
Dim path As String = "c:\acs\"
MsgBox("I have " + lines + " lines to do.")
If (Not System.IO.Directory.Exists(path)) Then
System.IO.Directory.CreateDirectory(path)
End If
Dim i As String = 0
For loops As Integer = 0 To RichTextBox1.Lines.Count - 1
Dim ac As String = RichTextBox1.Lines(looper).ToString
ac = ac.Substring(0, 3)
Dim strFile As String = path + ac + ".txt"
Dim sw As StreamWriter
sw = File.AppendText(strFile)
sw.WriteLine(RichTextBox1.Lines(looper))
sw.Close()
Label1.Text = String.Format("Processing item {0} of {1}", looper, lines)
looper = looper + 1
Next
MsgBox("done now")
End Sub
IT가 전체 파일을 메모리에로드 할 수 있습니다. 줄 단위로 읽거나 작은 파일로 나누어보십시오. –
다른 사람들이 아래에 암시했듯이, 내 충고는 rtb를 사용하지 않고 웹 개발자로서 무엇인지 확실하지 않지만 파일을 읽는 것을 처리하는 데있어 매우 표준적인 방법이 있습니다. http://msdn.microsoft. co.kr/ko-kr/library/system.io.streamreader.aspx. 나는 SR 객체에 성능 문제가 없었지만 ... http://msdn.microsoft.com/en-us/library/system.io.bufferedstream.aspx는 버퍼를 추가하는 방법을 제공하지만, SR 오브젝트에 이미 몇 가지 안전 장치가 있습니다. – RandomUs1r