0

I am loading a relatively huge file into RichTextBox in my desktop app.

I've tried many solutions seen on web including LoadFile, ReadToEnd, ReadAllText and ...

They work fine on my PC (and one similarly configured PC) with a rather small delay.

But on other PCs in the company, my released application just freezes loading file and sometimes shows error.

The error mentions problem to be at CRC.Form1.OpenFile()

    private void OpenFile()
    {
        OpenFileDialog _ofd = new OpenFileDialog();
        _ofd.Title = "Open Document";
        if (inputComboBox.SelectedItem == "From File (bare Hex)")
        {
            _ofd.Filter = "Text Files|*.txt|Hex Files|*.hex|Hxd Files|*.hxd|ROM Files|*.rom";
        }
        else if (inputComboBox.SelectedItem == "From File (Intel Hex)")
        {
            _ofd.Filter = "Hex Files|*.hex|Hxd Files|*.hxd|Text Files|*.txt|ROM Files|*.rom";
        }
        _ofd.FileName = string.Empty;
        if (_ofd.ShowDialog() == DialogResult.OK)
        {
            if (_ofd.FileName == String.Empty)
            {
                return;
            }
            else
            {
                //_LBA = 0;
                //StringBuilder oSB = new StringBuilder();
                //string _line;
                //inputTextBox.LoadFile(_ofd.FileName,RichTextBoxStreamType.PlainText);
                //FileStream _fs = new FileStream(_ofd.FileName, FileMode.Open);

                //using (StreamReader oStreamReader = new StreamReader(_ofd.FileName))
                //{
                //    while ((_line = oStreamReader.ReadLine()) != null)
                //    {
                //        inputTextBox.AppendText(_line+ "\n");
                //    }
                    //oSB = File.ReadAllLines(_ofd.FileName);
                    inputTextBox.Text = File.ReadAllText(_ofd.FileName);
                    //inputTextBox.Text = oStreamReader.ReadToEnd();
                    //inputTextBox.Text = oSB.ToString();
                //}
            }
        }
    }

This file is instantly loaded in Notepad++.

Does anybody know What should be done to make this loading faster (probably immediate) and lift the difference of behavior in different PCs?

Please remember, I don't have any problem in some PCs.

Here is a screenshot from the error in other PCs

Nayebifar
  • 1
  • 1

0 Answers0