out-of-memory exception thrown when using Find
-
I use the code below for a simple search function in a richtextbox. When I load larger files, and try to search it will always throw an out-of-memory exception. From the debugging it seems to be richTextBox.Find that is the culprit. For an example, searching File1 that is 1800kB is no problem but File2 at 17000kB will always throw the exception. Opening File2 in, for example Notepad, and search is no problem. Anyone knows why, is there a limitation with richTextBoxes and why can I then load the file with the Loadfile function? Is there any workaround for it? I also ran into another problem, with one specific file I don't get the exception when I search but instead "Failed to load resources from resource file. Please check your setup". I use the default settings and I did run the "fix application". Still it will crash with this message. Any fix for this? try { RichTextBox.SelectionColor = Color.Black; int searchEnd = RichTextBox.TextLength; searchStart = RichTextBox.Find(searchTextBox.Text, searchStart, searchEnd, RichTextBoxFinds.MatchCase); RichTextBox.SelectionColor = Color.Blue; //RichTextBox.SelectionFont = Font.Bold; RichTextBox.GetPositionFromCharIndex(searchStart); RichTextBox.Focus(); RichTextBox.ScrollToCaret(); if ( searchStart < searchEnd ) { searchStart++; } else { searchStart = 0; } } catch (Exception f) { MessageBox.Show("Failed to search " + searchFile + "\n" + f.ToString()); }
-
I use the code below for a simple search function in a richtextbox. When I load larger files, and try to search it will always throw an out-of-memory exception. From the debugging it seems to be richTextBox.Find that is the culprit. For an example, searching File1 that is 1800kB is no problem but File2 at 17000kB will always throw the exception. Opening File2 in, for example Notepad, and search is no problem. Anyone knows why, is there a limitation with richTextBoxes and why can I then load the file with the Loadfile function? Is there any workaround for it? I also ran into another problem, with one specific file I don't get the exception when I search but instead "Failed to load resources from resource file. Please check your setup". I use the default settings and I did run the "fix application". Still it will crash with this message. Any fix for this? try { RichTextBox.SelectionColor = Color.Black; int searchEnd = RichTextBox.TextLength; searchStart = RichTextBox.Find(searchTextBox.Text, searchStart, searchEnd, RichTextBoxFinds.MatchCase); RichTextBox.SelectionColor = Color.Blue; //RichTextBox.SelectionFont = Font.Bold; RichTextBox.GetPositionFromCharIndex(searchStart); RichTextBox.Focus(); RichTextBox.ScrollToCaret(); if ( searchStart < searchEnd ) { searchStart++; } else { searchStart = 0; } } catch (Exception f) { MessageBox.Show("Failed to search " + searchFile + "\n" + f.ToString()); }