public DialogImport(string file, CircuitProject target) { this.FileName = file; this.DataContext = this; this.InitializeComponent(); Mainframe mainframe = App.Mainframe; Thread thread = new Thread(new ThreadStart(() => { try { CircuitProject import = CircuitProject.Create(file); List <CircuitInfo> list = new List <CircuitInfo>(); foreach (LogicalCircuit circuit in import.LogicalCircuitSet) { list.Add(new CircuitInfo(circuit, target.LogicalCircuitSet.FindByLogicalCircuitId(circuit.LogicalCircuitId) == null)); } list.Sort(CircuitDescriptorComparer.Comparer); this.List = list; this.NotifyPropertyChanged(nameof(this.List)); } catch (SnapStoreException snapStoreException) { Tracer.Report("DialogImport.Load", snapStoreException); mainframe.ErrorMessage(Properties.Resources.ErrorFileCorrupted(file), snapStoreException); mainframe.Dispatcher.BeginInvoke(new Action(() => { this.Close(); })); } catch (Exception exception) { Tracer.Report("DialogImport.Load", exception); mainframe.ReportException(exception); mainframe.Dispatcher.BeginInvoke(new Action(() => { this.Close(); })); } })); //TextNote validation will instantiate FlowDocument that in some cases required to happened only on STA. thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Name = "ImportLoader"; thread.Priority = ThreadPriority.AboveNormal; thread.Start(); }