Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Async await WPF ViewModel Prism

$
0
0

I have a code that is currently working just fine, using Tasks to perform some work. However, I would like to changed it for use async await keywords.

public class TransmissionListService : ITransmissionListService
    {
public IEnumerable<Transmission> GetTransmissions()
        {
            if (sessionManager.IsUserLogged())
                return LiveAndOfflineTransmissions();

            return transmissionRepository.GetTransmissions();
        }
}

public class FilterViewModel : ViewModelBase
    {
public DelegateCommand RefreshList { get; private set; }

public FilterViewModel(ITransmissionListService transmissionListService, IMessageService messageService, ICategoryService categoryService)
        {
            this.transmissionListService = transmissionListService;
            this.messageService = messageService;
            this.categoryService = categoryService;

            Filter = new TransmissionListFilter();
            Categories = new ObservableCollectionBase<Category>();
            RefreshList = new DelegateCommand(ExecuteRefresh);
        }

public void ExecuteRefresh()
        {
            IncrementAsyncCalls("Atualizando transmissões...");
            Task.Factory.StartNew<IEnumerable<TransmissionPresenter>>(() =>
            {
                return transmissionListService.GetTransmissions().Select(t => new TransmissionPresenter(t)).ToList();
            })
            .ContinueWith((task) =>
            {
                DecrementAsyncCalls();
                if (task.IsFaulted)
                    messageService.ShowError(task.Exception.InnerException);
                else
                    Transmissions = CollectionViewSource.GetDefaultView(task.Result);
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }

I'm studying async await, but I'm just not quite there yet. I saw that works great with ASP.NET MVC 4 async actions. The MVC 4 framework was changed to support it, right?

How about WPF and ViewModel pattern?

If I put async in the ExecuteRefresh() method, it won't compile.

Any ideas? Any help would be appreciated.


Take a look at WPF FlashMessage
About.me


Viewing all articles
Browse latest Browse all 18858

Trending Articles