コード例 #1
0
        private void Init(string drive)
        {
            fileSystemService.Cleanup(drive);

            var driveNode = fileSystemService.GetDrive(drive);

            fileSystemService.StartWatcher(drive);

            TreeGrid.Root = new TreeGridNodeViewModel(driveNode);
            SetStatus($"Scanning drive: {drive} ...", loader: true);

            var ts = new CancellationTokenSource();

            Task.Delay(TimeSpan.FromMilliseconds(100), ts.Token)
            .ContinueWith(t => fileSystemService.Scan(drive, ts.Token), ts.Token)
            .ContinueWith(t =>
            {
                TreeGrid.Root = new TreeGridNodeViewModel(driveNode);
                if (ts.IsCancellationRequested)
                {
                    return;
                }

                SetStatus("Ready", loader: false);
                CalcStatistics(driveNode);
            }, ts.Token, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());


            treeCancellationTokenSource = ts;
        }