Beispiel #1
0
        internal static async Task HandleAsync(FileTransfer2ProgressEventArgs e)
        {
#if NOTIFICATIONHANDLER_DEBUGINFO
            Debug.WriteLine("Notification received: " + e.Progress + " (" + e.State.ToString() + ")");
#endif
            bool UISuccess = false;
            if ((CoreApplication.MainView.CoreWindow?.Dispatcher != null) && (MainPage.Current != null))
            {
                UISuccess = true;
#if NOTIFICATIONHANDLER_DEBUGINFO
                Debug.WriteLine("Dispatcher present and MainPage exists.");
#endif
                await DispatcherEx.RunTaskAsync(CoreApplication.MainView.CoreWindow.Dispatcher, async() =>
                {
                    //If app is minimized, send notifications but update the title too.
                    if (!Window.Current.Visible)
                    {
                        UISuccess = false;
                    }

#if NOTIFICATIONHANDLER_DEBUGINFO
                    Debug.WriteLine("Window.Current.Visible is true");
#endif

                    await MainPage.Current.FileTransferProgress(e);
                });
            }
        }
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            var dispatcher = Window.Current.Dispatcher;

            return(Task.Run <LoadMoreItemsResult>(
                       async() =>
            {
                uint resultCount = 0;
                IEnumerable <I> result = null;

                for (int i = 0; i < partsCount; i++)
                {
                    //dispatcher.RunAsync doesn't wait for task to be done, so we use this method instead.
                    await DispatcherEx.RunTaskAsync(dispatcher, async() =>
                    {
                        result = await source.GetPagedItems(currentPage++, itemsPerPart);

                        if (result == null || result.Count() == 0)
                        {
                            hasMoreItems = false;
                            LoadFinished?.Invoke(new EventArgs());
                        }
                        else
                        {
                            resultCount = (uint)result.Count();

                            foreach (I item in result)
                            {
                                if (VisibilityDecider(item))
                                {
                                    this.Add(item);
                                }
                            }
                        }
                    }, CoreDispatcherPriority.High);
                }
                return new LoadMoreItemsResult()
                {
                    Count = resultCount
                };
            }).AsAsyncOperation <LoadMoreItemsResult>());
        }