1
public partial class Form1 : Form
{
    System.Timers.Timer aTimer;
    double score, multiplier = 1;
    int numberOf1 = 0;
    public Form1()
    {
        InitializeComponent();
        aTimer = new System.Timers.Timer();
        aTimer.Interval = 1000;
        aTimer.Elapsed += ATimer_Elapsed;
        aTimer.Start();            
    }

    private void ATimer_Elapsed(object sender, ElapsedEventArgs e)
    {
        score += numberOf1 * 5;
        label1.Text = score.ToString();
    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        numberOf1 += 1;

    }
}

When I run it, it highlights label1.Text = score.ToString(); and gives me an error saying "Cross thread operation invalid".

I don't understand why it doesn't work, I tried googling it but I only found specific examples that I couldn't really copy.

0 Answers0