Click here to Skip to main content
15,924,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok, so here is the code I have to open my rules.txt file.... Whenever I try and edit the richtextbox it always crashes the program... Any ideas why.... Nothing showed up in the error list..


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace McMayhem.GUI
{
    public partial class TextFiles : Form
    {
        public TextFiles()
        {
            InitializeComponent();
        }


        private void txtRules_TextChanged(object sender, EventArgs e)
        {
        if (File.Exists("Rules.txt"))
            {
                txtRules.Text = "Rules for " + Server.Version + ":";
                foreach (string line in File.ReadAllLines(("Rules.txt")))
                {
                    txtRules.AppendText("\r\n           " + line);
                }
            }
        }
        }
        }
Posted

1 solution

For a software developer, there is not such thing as "crash". A software developer uses Debugger and always can see what's going on. First thing you need to do is to stop doing what you're doing and become a software developer. Today, not tomorrow!

Now, just think what you do! You do not show how your event handler is set up (who knows what txtRules_TextChanged means; there is no such event), but by the name of this method one could guess that this is used as a handler of the TextChanged event of your control textRules. Why RichTextBox? It should be just TextBox. No matter, let's see. On every change, you read and append some text to the same text box! It triggers TexChanged of the same text box again and… right, infinite recursion.

I have no idea why doing this, but this is how you screw up. Whole thing makes no sense. What was your ultimate goal? (Don't answer if you don't want :-).)

—SA
 
Share this answer
 
v3
Comments
Wayne Gaylard 9-Jun-11 6:58am    
May as well go
While(true)
{
}

Good Advice!

Forgot to vote.Oops.
Sergey Alexandrovich Kryukov 9-Jun-11 10:06am    
Thank you, Wayne.
No, "while true" is different, it will not eat up any stack and won't "crash" anything... :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900