Я работаю с классом timer в C# , когда вызываю timer.elapsed его show expection
i am working with Timer class in c# when i call timer.Elapsed its show expection
"Cross-thread operation not valid: Control 'dataGridView1' accessed from a thread other than the thread it was created on."
Что я уже пробовал:
System.Timers.Timer timer = new System.Timers.Timer(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer.Interval = 5000; timer.Elapsed += Timer_Elapsed; timer.AutoReset = true; timer.Enabled = true; } private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { GetAll(); } private void GetAll() { using (var db=new POSEntities()) { dataGridView1.DataSource= db.Products.ToList(); } }
NotPolitcallyCorrect
Ладно... и?