private async void createSessionToolStripMenuItem_Click(object sender, EventArgs evt) { try { using (GUISession session = new GUISession()) { session.ShowDialog(this); if (session.confirmed == true) { // Wait for running tasks. await Task.WhenAll(m_tasks); // Create the new task and add it to the queue. Task task; m_tasks.Add(task = CreateSession(session)); // Run the event. await Task.Run(() => task); // Remove it from the queue. m_tasks.Remove(task); } } } catch (Exception e) { Program.HandleException(this, e); } }
private async Task CreateSession(GUISession session) { // Shutdown an existing session. if (m_statTracker.SessionStarted()) { await m_statTracker.StartSession(); timer1.Stop(); } RegisterUserAndPrepareForInitialize(); m_statTracker.SetCountEvents(session.countStatsCheckBox.Checked); m_statTracker.StopPreparing(); await m_statTracker.Initialize((int)session.pastEventsNumber.Value + 1); if (m_statTracker.HasInitialized()) { await PrepareSession(); // Update overall weapons. await UpdateWeaponTextFields(m_statTracker.GetPlayer().weapons, this.weaponsGridView); UpdateMiscFields(); ManageSessionButtons(); HideUpdateText(); } else ShowUpdateText("Invalid ID"); ManageSessionButtons(); }