private void StartWatchCommandExecute(object obj) { var node = obj as DirectoryModel; this.ReinitializeToken(); Task.Run(async() => { while (true) { if (Token.IsCancellationRequested) { return; } if (!DirectoryService.CheckDirectory(node.FullName)) { if (Messenger.Go("Root folder was changed or deleted, clear the tree to load a new directory?", "Directory not found", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK) == MessageBoxResult.OK) { Application.Current.Dispatcher.Invoke(() => Directory = null); base.OnPropertyChanged(nameof(SelfDirectory)); LoadFlag = true; WatcherFlag = false; } else { Messenger.Go("чтобы загрузить новую директория - очистите дерево", "Message"); } return; } var transfer_directory = await DirectoryService.GetDirectory(node.FullName); var model_directory = await ConversionService.ConvertToModel(transfer_directory); Application.Current.Dispatcher.Invoke(() => Watcher.Check(node, model_directory)); } }, Token); }