コード例 #1
0
        /// <summary>
        /// Override this method to execute the command
        /// </summary>
        private async void OnExecute()
        {
            try
            {
                IsCancelled = false;
                await ExecuteOnMainThreadAsync();

                if (IsCancelled)
                {
                    return;
                }
                _ = JoinableTaskFactory.RunAsync(async() =>
                {
                    try
                    {
                        await Task.Yield();   // get off the caller's callstack.
                        await ExecuteAsync();
                        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                        await CompleteOnMainThreadAsync();
                    }
                    catch (OperationCanceledException)
                    {
                        // --- This exception is expected because we signaled the cancellation token
                        IsCancelled = true;
                        OnCancellation();
                    }
                    catch (AggregateException ex)
                    {
                        // --- ignore AggregateException containing only OperationCanceledException
                        if (ex.InnerException is OperationCanceledException)
                        {
                            IsCancelled = true;
                            OnCancellation();
                        }
                        else
                        {
                            OnException(ex);
                        }
                    }
                    finally
                    {
                        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                        await FinallyOnMainThreadAsync();
                        if (UpdateUiWhenComplete)
                        {
                            VsxAsyncPackage.UpdateCommandUi();
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExceptionHandler.Report(ex);
            }
        }
コード例 #2
0
        public static async void HandleDebugKeys(this SpectrumToolWindowViewModelBase vm, KeyEventArgs args)
        {
            var machine = vm.EmulatorViewModel.Machine;
            var state   = vm.EmulatorViewModel.MachineState;

            if (args.Key == Key.F5)
            {
                if (WindowsKeyboard.Modifiers == ModifierKeys.None)
                {
                    // --- Run in Debug mode
                    args.Handled = true;
                    machine.StartDebug();
                }
                else if (WindowsKeyboard.Modifiers == ModifierKeys.Control)
                {
                    args.Handled = true;
                    machine.Start();
                }
            }
            else
            {
                if (state != VmState.Paused)
                {
                    return;
                }

                if (args.Key == Key.F11 && WindowsKeyboard.Modifiers == ModifierKeys.None)
                {
                    // --- Step into
                    args.Handled = true;
                    await machine.StepInto();
                }
                else if (args.Key == Key.System && args.SystemKey == Key.F10 && WindowsKeyboard.Modifiers == ModifierKeys.None)
                {
                    // --- Step over
                    args.Handled = true;
                    await machine.StepOver();
                }
                else if (args.Key == Key.F12 && WindowsKeyboard.Modifiers == ModifierKeys.None)
                {
                    // --- Step over
                    args.Handled = true;
                    await machine.StepOut();
                }
            }

            if (args.Handled)
            {
                VsxAsyncPackage.UpdateCommandUi();
            }
        }