private void ResetButton_Click(object sender, RoutedEventArgs e) { // Use begin invoke or grid update will deadlock on same thread. ControlsHelper.BeginInvoke(() => RefreshList(true)); }
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { ControlsHelper.BeginInvoke(SendVibration); }
private void LogHelper_Current_NewException(object sender, EventArgs e) { ControlsHelper.BeginInvoke(ErrorsHelper.UpdateStatusErrorsLabel); }
static void CheckPlayList(bool added, bool changed) { // If new item was added or item status changed then... var items = playlist.ToArray(); if (added || changed) { // If nothing is playing then... if (!items.Any(x => x.Status == JobStatusType.Playing)) { // Get first item ready to play. var pitchedItem = items.FirstOrDefault(x => x.Status == JobStatusType.Pitched); //playlist.Remove(item); if (pitchedItem != null) { if (pitchedItem.StreamData != null) { // Takes WAV bytes without header. WavPlayer.ChangeAudioDevice(SettingsManager.Options.PlaybackDevice); var duration = (int)WavPlayer.Load(pitchedItem.StreamData); WavPlayer.Volume = SettingsManager.Options.Volume; WavPlayer.Play(); // Start timer which will reset status to Played pitchedItem.Duration = duration; pitchedItem.StartPlayTimer(); } else { // Must be outside begin invoke. int sampleRate = pitchedItem.WavHead.SampleRate; int bitsPerSample = pitchedItem.WavHead.BitsPerSample; int channelCount = pitchedItem.WavHead.Channels; // Takes WAV bytes without header. EffectsPlayer.ChangeAudioDevice(SettingsManager.Options.PlaybackDevice); EffectsPlayer.Load(pitchedItem.WavData, sampleRate, bitsPerSample, channelCount); EffectsPlayer.Volume = SettingsManager.Options.Volume; EffectsPlayer.Play(); // Start timer which will reset status to Played pitchedItem.StartPlayTimer(); } } } // If last item finished playing or any item resulted in error then clear then.. var lastItem = items.LastOrDefault(); if ((lastItem != null && lastItem.Status == JobStatusType.Played) || (items.Any(x => x.Status == JobStatusType.Error))) { ControlsHelper.BeginInvoke(() => { bool groupIsPlaying; int itemsLeftToPlay; lock (playlistLock) { ClearPlayList(null, out groupIsPlaying, out itemsLeftToPlay); } }); } else { ControlsHelper.BeginInvoke(() => { lock (threadIsRunningLock) { // If thread is not running or stopped then... if (!threadIsRunning) { threadIsRunning = true; ThreadPool.QueueUserWorkItem(ProcessPlayItems); } } }); } } }
void CheckAll() { lock (IssueListLock) { if (IssueList == null) { IssueList = new List <WarningItem>(); IssueList.Add(new ExeFileIssue()); IssueList.Add(new DirectXIssue()); IssueList.Add(new LeakDetectorIssue()); IssueList.Add(new MdkIssue()); IssueList.Add(new ArchitectureIssue()); IssueList.Add(new GdbFileIssue()); IssueList.Add(new IniFileIssue()); IssueList.Add(new DllFileIssue()); foreach (var item in IssueList) { item.FixApplied += Item_FixApplied; } } } bool clearRest = false; foreach (var issue in IssueList) { if (clearRest) { issue.Severity = IssueSeverity.None; } else { issue.Check(); } if (issue.Severity == IssueSeverity.Critical) { clearRest = true; } UpdateWarning(issue); } ControlsHelper.BeginInvoke(() => { var update2 = MainForm.Current.update2Enabled; if (Warnings.Count > 0) { // If not visible and must not ignored then... if (!Visible && !IgnoreAll) { StartPosition = FormStartPosition.CenterParent; var result = ShowDialog(MainForm.Current); // If ignore button was used then... if (IgnoreAll) { // If critical issues remaining then... if (Warnings.Any(x => x.Severity == IssueSeverity.Critical)) { // Close application. MainForm.Current.Close(); } // Update 2 haven't ran yet then.. else if (!update2.HasValue) { MainForm.Current.update2Enabled = true; } } } } else { if (Visible) { DialogResult = DialogResult.OK; } if (!update2.HasValue) { MainForm.Current.update2Enabled = true; } } }); }