private void Create_Snapshot_Click(object sender, RoutedEventArgs e) { Thread thread = new Thread(DoBackgroundQueryAndFileWrite); var parms = new ThreadParameters((System.DateTime) this.startDate.SelectedDate, (System.DateTime) this.endDate.SelectedDate, this.snapshotLocation.Text /*, this.PeopleFilename, this.ContributionsFilename*/); thread.Start(parms); }
private void DoBackgroundQueryAndFileWrite(object data) { ThreadParameters parms = (ThreadParameters)data; DateTime startDate = parms.StartDate; DateTime endDate = parms.EndDate; String snapshotLocation = parms.SnapshotLocation; Result result = new Result(); this.Dispatcher.BeginInvoke(new Action(() => { this.overlay.Visibility = System.Windows.Visibility.Visible; this.statusLabel.Content = "Querying People"; })); result = WritePeopleToFile(startDate, endDate); if (!result.Error) { this.Dispatcher.BeginInvoke(new Action(() => { this.statusLabel.Content = "Querying Contributions"; })); result = WriteContributionsToFile(startDate, endDate); } if (!result.Error) { this.Dispatcher.BeginInvoke(new Action(() => { this.statusLabel.Content = "Zipping Files"; })); result = ZipFiles(snapshotLocation); } if (result.Error) { LogError(result.ErrorMsg); this.Dispatcher.BeginInvoke(new Action(() => { this.statusLabel.Content = result.ErrorMsg; })); } else { LogInfo("Snapshot created successfully"); this.Dispatcher.BeginInvoke(new Action(() => { this.statusLabel.Content = "Snapshot Created."; MessageBox.Show("Snapshot file (" + snapshotLocation + ") ready for upload to Tools4Church."); })); } if (File.Exists(this.PeopleFilename)) { LogInfo("Deleting temporary people file: " + this.PeopleFilename); File.Delete(this.PeopleFilename); } if (File.Exists(this.ContributionsFilename)) { LogInfo("Deleting temporary contributions file: " + this.ContributionsFilename); File.Delete(this.ContributionsFilename); } this.Dispatcher.BeginInvoke(new Action(() => { this.overlay.Visibility = System.Windows.Visibility.Hidden; })); }