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(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)