private void counter_Tick(object sender, EventArgs e) { var availbleSeconds = 6 - (DateTime.Now - startMoment).Seconds; Timer = availbleSeconds.ToString(); if (availbleSeconds <= 0) { counter.Stop(); Dispatcher.BeginInvoke(async() => { IsCalculating = true; Timer = string.Empty; Quote = Quotes.GetRandomQuote(); if (cam != null) { try { await cam.CaptureImageAsync(); await startHardWork(); } catch (Exception) { MessageBox.Show("Can't calculate at this time! Sorry, try again!"); NavigationService.Navigate(new Uri(Pages.GeneralGameplay_Adventure, UriKind.RelativeOrAbsolute)); } } }); } }
async void timer_Tick(object sender, EventArgs e) { try { var availableSeconds = (DateTime.Now - this.startDate).Seconds; Timer = availableSeconds.ToString(); if (availableSeconds % 5 == 0) { Dispatcher.BeginInvoke(async delegate() { if (cam != null) { await cam.CaptureImageAsync(); } }); var rnd = new Random(); int randomLevel = rnd.Next(0, Constants.AvailableLevels + 1); while (selectedPhotos.Contains(randomLevel)) { randomLevel = rnd.Next(1, Constants.AvailableLevels + 1); } selectedPhotos.Add(randomLevel); string pic = "/Images/Levels/L" + randomLevel + ".JPG"; bmi = new BitmapImage(new Uri(pic, UriKind.Relative)); grimacePattern.Source = bmi; } if (availableSeconds > 19) { timer.Stop(); IsCalculating = true; Timer = string.Empty; Message = string.Empty; var worker = new BackgroundWorker(); DoWorkEventHandler workerHandler = null; this.FaceSdkHelper.Initialize(); for (int i = 1; i < 5; i++) { workerHandler = (a, b) => { startHardWork(i); }; worker.DoWork -= workerHandler; worker.DoWork += workerHandler; await worker.BeginWorkerAsync(); } IsCalculating = false; NavigationService.Navigate(new Uri(Pages.MainPage, UriKind.RelativeOrAbsolute)); } } catch (Exception ex) { MessageBox.Show("Something bad appeared! Going back.."); NavigationService.Navigate(new Uri(Pages.MainPage, UriKind.RelativeOrAbsolute)); } }