Unfortuanetly I get the following error
+ $exception {"Von diesem CollectionView-Typ werden keine Änderungen der \"SourceCollection\" unterstützt, wenn diese nicht von einem Dispatcher-Thread aus erfolgen."} System.NotSupportedException
My Code is a test Code in order to show the error
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApp5_Task_und_darstellun_test
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Transfer tr = new Transfer();
public MainWindow()
{
InitializeComponent();
ObservableCollection<int> Data = new ObservableCollection<int>();
new Task(() => { tr.GetData(Data); }).Start();
while (true)
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
// Code für den UI Thread
listView1.ItemsSource = Data;
CollectionViewSource.GetDefaultView(listView1.ItemsSource).Refresh();
}));
}
}
private void listView1_SelectionChanged(object sender,
SelectionChangedEventArgs e)
{
}
}
public class Transfer
{
public ObservableCollection<int> GetData(ObservableCollection<int> data)
{
while (true)
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
int d = i + j;
data.Add(d);
}
}return data;
}
}
}
}
How can I solve it. My real Code should Have a non ending for Loop and the results (as a List) should be written in a listview