User can perform an action and I add data to a collection that is bound to a DataGrid and that works fine.
But when there is a long running process that has multiple records added to the collection I never see the DataGrid updated until the process is over. What am I doing wrong? I am really new to this so I am sure the issue is something simple.
private ObservableCollection<StatusEntry> _collSe = new ObservableCollection<StatusEntry>();
public ObservableCollection<StatusEntry> CollSe
{
get { return _collSe; }
set
{
_collSe = value;
// NotifyPropertyChanged("CollSe");
}
}
CollSe.Add(new StatusEntry() { TimeStamp = DateTime.Now, Comment = "STARTED: Translating file to DataTable" });
DataTable dt = ExcelHelper.ReadAsDataTable(tbFileName.Text);
CollSe.Add(new StatusEntry() { TimeStamp = DateTime.Now, Comment = "COMPLETE: Translating file to DataTable" });
EDIT:
More clearly here is what I tried.. Still does not update the UI until the end though
private void btnProcessFile_Click(object sender, RoutedEventArgs e)
{
//THis should happen as soon as the button is pressed
ThreadStart job = new ThreadStart(() =>
{
for (int i = 0; i < 20; i++)
{
// The new thread puts UI operations in the dispatching queue
Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
{
CollSe.Add(new StatusEntry() { TimeStamp = DateTime.Now, Comment = "Happy Tools STARTED" });
}));
}
});
Thread thread = new Thread(job);
thread.Start();
//The another minute of processing here.....