1

I used this code thinking that the app did not stop but it was not like that. How do you correctly dispatcher - RunAsync in UWP?

Code:

public sealed partial class MainPage : Page
{
    List<Grid> listaGrid = new List<Grid>();
    public MainPage()
    {
        this.InitializeComponent();
    }

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
            for (int a = 0; a <= 10000000; a++)
            {
                listaGrid.Add(new Grid());
            }
        });
    }
}

How can I correctly use Dispatcher - RunAsync?

Always thank you in advance..!

Luca
  • 21
  • 7
  • It is not entirely clear what you're asking, but the marked duplicate covers all the bases. Without a good [mcve], it's impossible to say what's wrong with your code. But, based on the tiny bit you've offered here, it's safe to say you're probably doing it _all wrong_. Simply property binding updates are marshaled back to UI automatically, and if you have `await`, you should compose your long-running tasks as awaitable tasks where UI interaction occurs _after_ the `await` completes, not while you're waiting for it to do so. You really shouldn't have to access the dispatcher directly at all. – Peter Duniho Nov 26 '17 at 19:56
  • I have updated the question.. – Luca Nov 26 '17 at 20:15

0 Answers0