Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my program includes the following code:

C#
try
{
    PrivateRichTextBox1.Text = PrivateRichTextBox1.Text + "Me: " + privateMessageTextBox.Text + "\n";
    PrivateRichTextBox1.SelectionStart = PrivateRichTextBox1.Text.Length;
    PrivateRichTextBox1.ScrollToCaret();
}
catch
{
}


it works perfectly but sometimes the program just stops on the line:

C#
PrivateRichTextBox1.Text = PrivateRichTextBox1.Text + "Me: " + privateMessageTextBox.Text + "\n";


and give me this error:
attempted to read or write protected memory.this is often an indication that other memory is corrupt.

what does that mean ??? what should I do to overcome this error???

thanks in advance :)
Posted
Updated 2-Oct-11 18:38pm
v2
Comments
Bala Selvanayagam 2-Oct-11 9:19am    
I could not re-create the same error message, Is there any specefic sequence or order i need to operate to recreate ?
George_Rasmi 2-Oct-11 12:16pm    
you have to write a text in the PrivateMessageTextBox and press Enter to add this text to the PrivateRichTextBox1 ... the code of the PrivateMessageTextBox key_up (Enter) event is this:

private void PrivateMessageTextBox_KeyUp_1(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
PrivateMessageTextBox.Text = PrivateMessageTextBox.Text.Replace("\r\n", "");
if (PrivateMessageTextBox.Text != "")
{
try
{
PrivateRichTextBox1.Text = PrivateRichTextBox1.Text + "Me: " + PrivateMessageTextBox.Text + "\n";
PrivateRichTextBox1.SelectionStart = PrivateRichTextBox1.Text.Length;
PrivateRichTextBox1.ScrollToCaret();
}
catch
{
}
PrivateMessageTextBox.Text = "";
}
}
}
}

but to get that error you will have to execute this function very fast and for many times (I mean try to write one character and then press enter then immediately re write a character and press enter and keep doing this very fast and for many times until the program stops and gives you that error)
[no name] 2-Oct-11 9:22am    
That's so strange!
I don't think there is any exception here? Looking at your question I have thought of some kind of accessing and editing some value at some memory address, but your problem is really strange!
Hope others can help you!
Richard MacCutchan 2-Oct-11 12:06pm    
Are you sure that both the text box and message box always have some content at the first line above? Add checks for null content before that statement to verify.
George_Rasmi 2-Oct-11 12:20pm    
I did that too, but it's not the problem because when I test the program I always write something in the text box

Have a look at below link.

MSDN Forum
 
Share this answer
 
Comments
George_Rasmi 2-Oct-11 12:20pm    
it didn't help :(
 
Share this answer
 

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