private void stackButton_Click(object sender, RoutedEventArgs e) { // Try to convert to blocks List <BlockBase> blocks = null; try { blocks = vm.LS.ToBlocks(); } catch (Exception ex) { MessageBox.Show($"Error while converting to blocks, please check the syntax!\n{ex.Message}"); vm.View = StackerView.LoliScript; // Make sure the view is back to LoliScript return; } // Add the block viewmodels to the stack vm.ClearBlocks(); foreach (var block in blocks) { vm.AddBlock(block, -1); } // Clear the last Block Info page vm.CurrentBlock = null; BlockInfo.Content = null; // Switch tab vm.View = StackerView.Blocks; stackerTabControl.SelectedIndex = 1; }
private void stackButton_Click(object sender, RoutedEventArgs e) { // Try to convert to blocks List <BlockBase> blocks = null; var action = new Action(async() => { try { blocks = vm.LS.ToBlocks(); } catch (Exception ex) { await Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate { MessageBox.Show($"Error while converting to blocks, please check the syntax!\n{ex.Message}"); }); vm.View = StackerView.LoliScript; // Make sure the view is back to LoliScript return; } // Add the block viewmodels to the stack try { await Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate { vm.ClearBlocks(); }); } catch (Exception ex) { } blocks.ForEach(async block => { await Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate { vm.AddBlock(block); }); }); // Clear the last Block Info page vm.CurrentBlock = null; Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate { BlockInfo.Content = null; }); // Switch tab vm.View = StackerView.Blocks; await Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate { stackerTabControl.SelectedIndex = 1; }); }); try { taskSwitchView?.Dispose(); if (sender is Button) { taskSwitchView = Task.Run(action); } else { taskSwitchView = Task.Run(action); taskSwitchView.Wait(); taskSwitchView.Dispose(); } } catch { } }