I'm new to C# so take it easy on me please, but I'm running into a problem where I'm unable to change the state of the visibility of a label within a thread that I've made.
The label I'm trying to change is called DEBUG, and isn't related in any way to Label1
Here is the code for the form (DebugCount is an integer that is defined in the code for the form itself):
public partial class GamePage : Form
{
public GamePage()
{
InitializeComponent();
Thread DebugThread = new(new ThreadStart(DebugHandler));
DebugThread.Start();
}
private void label1_Click(object sender, EventArgs e)
{
DebugCount++;
}
public void DebugHandler()
{
while(true)
{
if(DebugCount >= 5)
{
DEBUG.Visible = true;
break;
}
}
}
}
Here is the error: System.InvalidOperationException: 'Cross-thread operation not valid: Control 'GamePage' accessed from a thread other than the thread it was created on.'