InvokeMainThread Xamarin

1

I'm having a problem invoking a UIThread in PCL.

I made a method like this:

    private void PopularConteudo()
    {

        Task<List<Departamento>> taskDep = new Task<List<Departamento>>(() =>
        {
            departamentos = departamentoDal.GetAll();
            return departamentos.ToList();
        });
        taskDep.Start();
        taskDep.Wait();

        PopularCarouselDepartamentos();

        Task<List<Categoria>> taskCat = new Task<List<Categoria>>(() =>
        {
            categorias = categoriaDal.GetAllByDepartamento(carouselViewDepartamentos.Item as Departamento).ToList();
            PopularCarouselCategorias();
            return categorias.ToList();
        });

        taskCat.Start();
        taskCat.Wait();

        Task<List<Produto>> taskProd = new Task<List<Produto>>(() =>
        {
            produtos = produtoDal.GetAllByCategoria(carouselViewCategorias.Item as Categoria);
            return produtos.ToList();
        });
        taskProd.Start();
        taskProd.Wait();
        PopularListViewProdutos();
    }

private void PopularCarouselDepartamentos()
{

        Device.BeginInvokeOnMainThread(()=> {
            try
            {
                carouselViewDepartamentos.ItemsSource = departamentos;
            }
            catch (Exception e) // handle whatever exceptions you expect
            {
                //Handle exceptions
            }
        });
}

What happens is that when I invoke the PopularCarouselDefinition () method it simply does not enter the try-catch instruction block.

Consequently the Carousel is not populated and I need it to popularize the other contents.

All popular methods are very similar.

Does anyone know how to solve this problem?

    
asked by anonymous 18.03.2017 / 01:49

0 answers