I am experimenting Parallel Programming for the first time and i am using it to improve the speed filtering on the Telerik Scheduler control.
this is the code i am using to filter appointments by room, ex:
Task.Factory.StartNew(() =>
{
SchedulerView view = this.radScheduler1.ActiveView;
//ConcurrentBag<Classes.Appointment> _bag;
if (InvokeRequired) Invoke((Action)(delegate
{
this.radScheduler1.Appointments.BeginUpdate();
_itemsview = appointments.AsEnumerable().Where(app => app.Start >= view.StartDate && app.End < view.EndDate.AddDays(1)).ToList();
//_bag = new ConcurrentBag<Classes.Appointment>(_itemsview);
Parallel.ForEach(_itemsview, item =>
{
if (_unidades.Contains(item.Room.ToString()))
{
item.Visivel = true;
}
else
{
item.Visivel = false;
}
});
this.radScheduler1.Appointments.EndUpdate();
this.radScheduler1.Select();
}));
});
What happens next, is that i can see sometimes other appointments that felled of the filter. I know that the number of appointments filtered is always right, but not always i see the right appointments on the screen. What is happening ?