i want to remove entities on a background thread but we can not delete entities on another thread that it has be created on so how can i do that and keep the ui responding? i'm tying to use the backgroundworker class here is the code
void deletePeriodWorker_DoWork(object sender, DoWorkEventArgs e)
{
Thread.Sleep(3000);
List<Period> selectedPeriods = e.Argument as List<Period>;
foreach (Period period in selectedPeriods)
{
while (period.Transactions.Count > 0)
{
Transaction transaction = period.Transactions[0];
this.Dispatcher.Invoke(new Action(() => context.Transactions.Remove(transaction)),
System.Windows.Threading.DispatcherPriority.Normal);
}
this.Dispatcher.Invoke(new Action(() => context.Periods.Remove(period)),
System.Windows.Threading.DispatcherPriority.Normal);
}
this.Dispatcher.Invoke(new Action(() => context.SaveChanges()),
System.Windows.Threading.DispatcherPriority.Normal);
}