private void AddNews() { int startPos = 8; int posVal = 340; foreach (var element in News) { System.Windows.Application.Current.Dispatcher.BeginInvoke((Action) delegate { NewsControl control = new NewsControl(); control.Title.Text = element.Title; control.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; control.Link = element.Link; control.Content.Text = element.Description; control.PartiallyBluredDoge.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\" + element.LocalImage)); control.Margin = new Thickness(startPos, 40, 0, 0); startPos += posVal; Dispatcher.BeginInvoke((MethodInvoker)(() => { NewsScrollGrid.Children.Add(control); })); }); } }
private void AddNews(List <NewsRepository> news) { int startPos = 8; int posVal = 288; news.AsParallel().ForAll((element) => { System.Windows.Application.Current.Dispatcher.BeginInvoke((Action) delegate { NewsControl control = new NewsControl(); control.Title.Text = element.Title; control.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; control.Link = element.Link; control.Margin = new Thickness(startPos, 15, 0, 0); startPos += posVal; Dispatcher.BeginInvoke((MethodInvoker)(() => { NewsScrollGrid.Children.Add(control); })); }); }); }