void gpsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { GpsWorkerArguemnts args = (GpsWorkerArguemnts)e.Result; mainForm.WorkFinished(); // ask the user: do it now? string text = String.Format( "The GPS time is between {0} and {1}.\nThe picture time is between {2} and {3} ({4} and {5}).\n\nContinue?", args.log.FirstTime, args.log.LastTime, args.firstPicture.Add(args.log.Offset), args.lastPicture.Add(args.log.Offset), args.firstPicture, args.lastPicture); if (MessageBox.Show(text, "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { gpsBackgroundWorker2.RunWorkerAsync(args); } else { foreach (PictureMetaData pmd in args.pictures) { if (pmd != currentPicture) { pmd.Close(); } } RestartOtherWorker(); } }
void gpsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = (BackgroundWorker)sender; backgroundWorker.ReportProgress(0); GpsWorkerArguemnts args = (GpsWorkerArguemnts)e.Argument; List <string> filenames = this.GetAllFileList(false); // compute the timespan of all pictures DateTime firstPicture = new DateTime(4000, 1, 1); DateTime lastPicture = new DateTime(1, 1, 1); List <PictureMetaData> pictures = new List <PictureMetaData>(); int i = 0; foreach (string filename in filenames) { i++; PictureMetaData pmd; if (this.currentPicture != null && this.currentPicture.Filename == filename) { pmd = currentPicture; } else { pmd = new PictureMetaData(filename); } if (pmd.ExifOriginalDateTime.HasValue) { DateTime time = pmd.ExifOriginalDateTime.Value; if (time > lastPicture) { lastPicture = time; } if (time < firstPicture) { firstPicture = time; } pictures.Add(pmd); } backgroundWorker.ReportProgress(i * 100 / filenames.Count); } e.Result = new GpsWorkerArguemnts(args.log, firstPicture, lastPicture, pictures); }
void gpsBackgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = (BackgroundWorker)sender; backgroundWorker.ReportProgress(0); GpsWorkerArguemnts args = (GpsWorkerArguemnts)e.Argument; int i = 0; foreach (PictureMetaData pmd in args.pictures) { i++; UpdateGpsData(pmd, args.log); if (pmd != currentPicture) { pmd.Close(); } backgroundWorker.ReportProgress(i * 100 / args.pictures.Count); } }