private void openFile(string filepath) { try { DataSourceMap.InsertResult insertResult = dataSources.Insert(filepath, null); if (insertResult.WasInserted) { // file was not already open; create a new data source insertResult.Element.Value = new DataSource(filepath); insertResult.Element.Value.StatusReport += new StatusReportEventHandler(openFile_StatusReport); insertResult.Element.Value.ProgressReport += new ProgressReportEventHandler(openFile_ProgressReport); insertResult.Element.Value.SetInputFileCompleted += new SetInputFileCompletedEventHandler(openFile_SetInputFileCompleted); } else { GraphForm.CreateNewWindow(this, insertResult.Element.Value, true); } // update recent files list recentFilesMenu.AddFile(filepath, Path.GetFileName(filepath)); recentFilesMenu.SaveToRegistry(); } catch (Exception ex) { string message = ex.Message; if (ex.InnerException != null) { message += "\n\nAdditional information: " + ex.InnerException.Message; } MessageBox.Show(message, "Error opening source file", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, false); } }
private void openFile_SetInputFileCompleted(object sender, SetInputFileCompletedEventArgs e) { if (InvokeRequired) { CreateNewWindowCallback d = new CreateNewWindowCallback(GraphForm.CreateNewWindow); Invoke(d, new object[] { this, e.DataSource, true }); } else { GraphForm.CreateNewWindow(this, e.DataSource, true); } }