1

I have made my program using Visual Studio.

I would like a TextBox to display the contents of file, but when the contents of file reaches hundreds of megabytes in size, a SystemOutOfMemoryException message appears.

How many bytes can fit into a textbox? So that I can limit the size of the data I read from the file.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
jeje
  • 11
  • 1
  • 1
    Displaying several hundred megabytes in a single Textbox is not going to make for a good user experience. Perhaps you should look at doing this a different way. –  Sep 23 '13 at 03:58
  • 2
    possible duplicate of [vb.net 2008 textbox max length](http://stackoverflow.com/questions/1810865/vb-net-2008-textbox-max-length) – bansi Sep 23 '13 at 03:59
  • 1
    "How much the number of bytes that can fit a textbox" - How much free memory does the computer have at that time? – Tim Sep 23 '13 at 03:59
  • @MikeW unless the OP is creating a notepad-like application. – Federico Berasategui Sep 23 '13 at 04:04
  • 2
    Oh yes - several hundred megabytes in Notepad is a wonderful experience. –  Sep 23 '13 at 04:05

1 Answers1

0

This sounds like a memory problem not a textbox problem which should have effectively unlimited capacity - max size of string = 2GB.

A dirty way is to catch the OOM exception and try again with half the size or so. Perhaps you can break it into smaller sections and store them in a temporary file to be loaded on demand.

If it's a really demanding application you can also target x64 or AnyCPU to get access to more memory on 64 bit Windows.

user1318499
  • 1,327
  • 11
  • 33