I don’t have much experience with multi threading so I am wondering how to refresh my Data Grid View every, for example, two seconds.
Basically, when the user is on a certain tab, and they have selected ‘Currently Importing’, it should call a method GetNotImportedFiles() every n seconds, the method then calls the SP and binds the DataSet.
Obviously, I need a timer which will do this every n seconds but I need it to execute the method as a background worker but communicate with the UI thread to update the DataGridView.
If you need any code, please ask.
UPDATE: I have implemented a timer but it never seems to hit the method for timerTick?
In my designer I have the code:
this.refreshTimer.Interval = 1000;
this.refreshTimer.Tick += new System.EventHandler(this.refreshTimer_Tick);
My understanding is that refreshTimer_Click should be called every 1 second. But I have a breakpoint in the code that is never hit?
private void refreshTimer_Tick(object sender, EventArgs e)
{
if (searchComboBox.Text.Equals("Currently Importing"))
{
try
{
DataSet temp = EngineBllUtility.GetNotImportedFiles(connectionString);
if (temp != null)
importFileGridView.DataSource = temp.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Mske use of : Timer in C# which allow to query data after every timer tick…you can visite link for more detail about timer.