I have a DataGrid on my main page that is full of Employees. Each Employee has an "in" status - this is modified based on whether the Employee is currently in the building or not.
I need to consistently update this DataGrid as people will be entering or leaving the building throughout the day. This means I will be sending MySQL queries somewhere between every 1-5 seconds until the user clicks on a button to navigate to another page.
I have tried the most simple and obvious solution, a While loop however this freezes and locks the UI. How can I create a loop that runs and queries MySQL without locking the UI?
EDIT: Attempted Answer
public void PeriodicCall()
{
var employeeDS = new EmployeeDataService();
int i = 1;
Timer timer = new Timer(
state => {
Employees = employeeDS.HandleEmployeeSelect();
FilteredView = CollectionViewSource.GetDefaultView(Employees);
Application.Current.Dispatcher.BeginInvoke(new Action(() => {
dataGrid.ItemsSource = FilteredView;
testLabel.Content = "Who's Who " + i;
i++;
}));
},
null, //no object as Callback parameter
TimeSpan.FromSeconds(0), //start in x millisec
TimeSpan.FromSeconds(1)); //time between call
}