2

First of all, sorry for my poor English.

I'm working on my .NET project and I need to get a large text from my server to textbox. Problem is that my text files from the server have about 50000-100000 lines (about 20mb-50mb) in single file and every time when I try to load it my program freeze and then crashes.

Dim LargeText As String = "https://example.com/files/LargeText.txt"        
Dim reader As StreamReader = New StreamReader(client.OpenRead(LargeText))
            TextBox1.Text = reader.ReadToEnd

This is the code I use for reading text to textbox. I guess there is a way to load it in the background or something else, I don't know.

mx0
  • 6,445
  • 12
  • 49
  • 54
Luka Pop
  • 55
  • 5
  • 1
    There are some suggestions for this issue [here](https://stackoverflow.com/questions/4273699/how-to-read-a-large-1-gb-txt-file-in-net). TLDR: use ReadLine instead of ReadToEnd, or the MemoryMappedFile class – soohoonigan Oct 13 '17 at 15:27
  • 1
    Also, TextBox has a limit to how long the text can be (found this out the hard way). RichTextBox can handle more text. – dwilliss Oct 13 '17 at 16:12
  • 1
    @dwilliss When the MaxLength property is set to 0, the maximum length of the text that can be entered in the control is limited only by available memory. – Sorceri Oct 13 '17 at 16:20
  • I ran the code in your example and it worked here. I created a 220mg text file with approx 120,000 lines and named it LargeText.txt, changed the path to a local path on my C:\ drive. The form did go into a (non responsive) state for a short span but came to life after it read the file. It loaded all 220mg of text into the text control without any errors. Speaking of errors, did you see an error message? if so can you tell us what the error message said? – Rose Oct 13 '17 at 16:56

0 Answers0