این کد چرا اجرا نمی شه٬ من Thread دیگه ایجاد نکردم ولی میگه cross Thread Operation no valid?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace Test_threading
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void compt()
{
while (true)
{
listBox1.Items.Add(listBox1.Items.Count);
}
}
private void button1_Click(object sender, EventArgs e)
{
ThreadStart Ts = new ThreadStart(compt);
Thread Tr = new Thread(Ts);
Tr.Start();
}
}
}