Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I get the following error with this code below this text.
Message=Cross-thread operation not valid: Control 'richTextBox1' accessed from a thread other than the thread it was created on.
Can someone help me?
private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
{
if (saved == true)
{
saved = false;
richTextBoxInfo.Invoke((MethodInvoker)(() => richTextBoxInfo.Text = richTextBoxInfo.Text));
File.WriteAllText(@"wininfo.txt", richTextBoxInfo.Text);
timerSave.Stop();
MessageBox.Show("Saved!");
}
}
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Try changing two lines:
string text = null;
richTextBoxInfo.Invoke((MethodInvoker)(() => text = richTextBoxInfo.Text));
File.WriteAllText(@"wininfo.txt", text);
Also check if the saved variable is used correctly.