Exemple #1
0
        private async Task LoadWithNestedScopesExecute()
        {
            using (var externalBusyBox = new MessageBusyBox(this, "1st part."))
            {
                Items = string.Empty;

                for (int i = 0; i < 5; i++)
                {
                    Items += i.ToString() + Environment.NewLine;
                    externalBusyBox.UpdateMessage($"1st part: {i + 1} (of 5)");

                    await Task.Delay(250);
                }

                using (var innerBusyBox = new MessageBusyBox(this, "2nd part."))
                {
                    for (int i = 0; i < 5; i++)
                    {
                        Items += i.ToString() + Environment.NewLine;
                        innerBusyBox.UpdateMessage($"2nd part: {i + 1} (of 5)");

                        await Task.Delay(250);
                    }

                    using (var oneMoreBusyBox = new CancellationBusyBox(this, "3rd part."))
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            Items += i.ToString() + Environment.NewLine;
                            oneMoreBusyBox.UpdateMessage($"3rd part: {i + 1} (of 5)");

                            if (oneMoreBusyBox.BusyCts.IsCancellationRequested)
                            {
                                if (MessageBox.Show(
                                        "Are you sure to abort the operation?",
                                        "Warning",
                                        MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes)
                                {
                                    break;
                                }

                                oneMoreBusyBox.BusyCts = new CancellationTokenSource();
                            }

                            await Task.Delay(250);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private async Task LoadWithMessageExecute()
        {
            using (var busyBox = new MessageBusyBox(this, "Loading started."))
            {
                Items = string.Empty;

                for (int i = 0; i < 5; i++)
                {
                    Items += i.ToString() + Environment.NewLine;
                    busyBox.UpdateMessage($"Loaded: {i + 1} (of 5)");

                    await Task.Delay(250);
                }
            }
        }