i try to develop a equivalent to a android app (just for fun / 2 learn) and i try to add round about 3500 UserControls to my GUI in a StackPanel.
One UserControl contain 2 textblocks (titel and subtitle), two buttons and one image.
If i add the controls in the UI thread the thread will be blocked for round about 6 sec. But an asynchronous thread will throw an exception:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
var task = Task.Run(async () =>
{
MyUserControl1 News = new MyUserControl1();
// EXAMPLE
for (int i = 0; i < 3500; i++)
{
News= new MyUserControl1();
News.Titel = i + " Titel";
News.Untertitel = i + " Untertitel";
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
UserControlCollection.Children.Add(News);
});
}
});
What can I do to resolve this fault? thx for your help
User contributions licensed under CC BY-SA 3.0