コード例 #1
0
        private void SetContents()
        {
            ContentsInternal = new ObservableCollection <MainWindowFile>();
            //TODO need to work out how to cancel this if 'this' is disposed / released before the task completes
            SetContentsTask = Task.Run(() =>
            {
                StartLongOperation();
                try
                {
                    IEnumerable <IFileSystemObject> directoryContents = _DirectoryObject.GetContentsEnumerable();
                    var aLot = directoryContents.Take(10);

                    while (aLot.Count() > 0)
                    {
                        UiDispatcher.Invoke(() =>
                        {
                            aLot.Select(CreateNewFile).ToList().ForEach(c => _ContentsInternal.Add(c));
                        }
                                            );
                        //var firstItem = ContentsInternal.FirstOrDefault();
                        //if (firstItem != null) { SelectedFile = firstItem; }
                        directoryContents = directoryContents.Skip(10);
                        aLot = directoryContents.Take(10);
                    }
                }
                finally
                {
                    EndLongOperation();
                }
            });
        }