private void Window_Loaded(object sender, RoutedEventArgs e) { try { String path = "Input.txt"; List <String> lines = LineByLineReader.ReadInput(path); foreach (String line in lines) { this.expressions.Add(new ExpressionSimplifier.Expression( line, ExpressionParser.BuildTree(line))); } lbExpressions.ItemsSource = this.expressions; FillTransformationsComboBox(); } catch (Exception ex) { // Workaround // 64bit machines are unable to properly throw the errors during a Window_Loaded event. // http://stackoverflow.com/questions/4807122/wpf-showdialog-swallowing-exceptions-during-window-load BackgroundWorker loaderExceptionWorker = new BackgroundWorker(); loaderExceptionWorker.DoWork += ((exceptionWorkerSender, runWorkerCompletedEventArgs) => { runWorkerCompletedEventArgs.Result = runWorkerCompletedEventArgs.Argument; }); loaderExceptionWorker.RunWorkerCompleted += ((exceptionWorkerSender, runWorkerCompletedEventArgs) => { throw (Exception)runWorkerCompletedEventArgs.Result; }); loaderExceptionWorker.RunWorkerAsync(ex); } }
static void Main(String[] args) { String path = "Input.txt"; List <String> lines = LineByLineReader.ReadInput(path); List <ExpressionNode> trees = new List <ExpressionNode>(); foreach (String line in lines) { trees.Add(ExpressionParser.BuildTree(line)); } foreach (var item in trees) { Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); if (item == null) { Console.WriteLine("Invalid parentheses\n"); continue; } Dimension dim; try { dim = item.GetDimension(); Console.WriteLine("dim: [" + dim.M + "," + dim.N + "]\n"); Console.WriteLine("cost: " + item.Cost() + "\n"); } catch (ApplicationException appEx) { Console.WriteLine(appEx.Message + "\n"); } finally { Console.WriteLine(item.ToString()); } } Console.ReadKey(); }