コード例 #1
0
ファイル: App.xaml.cs プロジェクト: pva-br/Dopamine
        private void ExecuteEmergencyStop(Exception ex)
        {
            // This is a workaround for a bug in the .Net framework, which randomly causes a System.ArgumentNullException when
            // scrolling through a Virtualizing StackPanel. Scroll to playing song sometimes triggers this bug. We catch the
            // Exception here, and do nothing with it. The application can just proceed. This prevents a complete crash.
            // This might be fixed in .Net 4.5.2. See here: https://connect.microsoft.com/VisualStudio/feedback/details/789438/scrolling-in-virtualized-wpf-treeview-is-very-unstable
            if (ex.GetType().ToString().Equals("System.ArgumentNullException") & ex.Source.ToString().Equals("PresentationCore"))
            {
                LogClient.Warning("Avoided Unhandled Exception: {0}", ex.Message);
                return;
            }

            LogClient.Error("Unhandled Exception. {0}", LogClient.GetAllExceptions(ex));

            // Close the application to prevent further problems
            LogClient.Info("### FORCED STOP of {0}, version {1} ###", ProductInformation.ApplicationName, ProcessExecutable.AssemblyVersion());

            // Stop playing (This avoids remaining processes in Task Manager)
            var playbackService = ServiceLocator.Current.GetInstance <IPlaybackService>();

            playbackService.Stop();

            // Emergency save of the settings
            SettingsClient.Write();

            Application.Current.Shutdown();
        }
コード例 #2
0
ファイル: LifetimeService.cs プロジェクト: spramij/Dopamine
        public async Task PerformClosingTasksAsync()
        {
            LogClient.Info("Performing closing tasks");

            // Write settings
            DateTime startTime = DateTime.Now;

            SettingsClient.Write();
            LogClient.Info($"Write settings. Time required: {Convert.ToInt64(DateTime.Now.Subtract(startTime).TotalMilliseconds)} ms");

            // Save queued tracks
            startTime = DateTime.Now;

            if (this.playbackService.IsSavingQueuedTracks)
            {
                while (this.playbackService.IsSavingQueuedTracks)
                {
                    await Task.Delay(50);
                }
            }
            else
            {
                await this.playbackService.SaveQueuedTracksAsync();
            }

            LogClient.Info($"Save queued tracks. Time required: {Convert.ToInt64(DateTime.Now.Subtract(startTime).TotalMilliseconds)} ms");

            // Stop playing
            startTime = DateTime.Now;
            this.playbackService.Stop();
            LogClient.Info($"Stop playback. Time required: {Convert.ToInt64(DateTime.Now.Subtract(startTime).TotalMilliseconds)} ms");

            // Update file metadata
            startTime = DateTime.Now;
            await this.metadataService.ForceSaveFileMetadataAsync();

            LogClient.Info($"Update file metadata. Time required: {Convert.ToInt64(DateTime.Now.Subtract(startTime).TotalMilliseconds)} ms");


            // Save playback counters
            startTime = DateTime.Now;

            if (this.playbackService.IsSavingPlaybackCounters)
            {
                while (this.playbackService.IsSavingPlaybackCounters)
                {
                    await Task.Delay(50);
                }
            }
            else
            {
                await this.playbackService.SavePlaybackCountersAsync();
            }

            LogClient.Info($"Save playback counters. Time required: {Convert.ToInt64(DateTime.Now.Subtract(startTime).TotalMilliseconds)} ms");

            this.MustPerformClosingTasks = false;
        }
コード例 #3
0
        private async Task PerformClosingTasksAsync()
        {
            LogClient.Info("Performing closing tasks");
            this.ShowClosingAnimation();

            // Write the settings
            // ------------------
            LogClient.Info("Writing settings");
            SettingsClient.Write();

            // Save queued tracks
            // ------------------
            LogClient.Info("Saving queued tracks");
            if (this.playbackService.IsSavingQueuedTracks)
            {
                while (this.playbackService.IsSavingQueuedTracks)
                {
                    await Task.Delay(50);
                }
            }
            else
            {
                await this.playbackService.SaveQueuedTracksAsync();
            }

            // Stop playing
            // ------------
            LogClient.Info("Stopping playback");
            this.playbackService.Stop();

            // Update file metadata
            // --------------------
            LogClient.Info("Updating file metadata");
            await this.metadataService.SafeUpdateFileMetadataAsync();

            // Save track statistics
            // ---------------------
            LogClient.Info("Saving playback counters");
            if (this.playbackService.IsSavingPlaybackCounters)
            {
                while (this.playbackService.IsSavingPlaybackCounters)
                {
                    await Task.Delay(50);
                }
            }
            else
            {
                await this.playbackService.SavePlaybackCountersAsync();
            }

            LogClient.Info("### STOPPING {0}, version {1} ###", ProductInformation.ApplicationName, ProcessExecutable.AssemblyVersion().ToString());

            this.mustPerformClosingTasks = false;
            this.Close();
        }
コード例 #4
0
ファイル: App.xaml.cs プロジェクト: one3chens/Knowte
        private void ExecuteEmergencyStop(Exception ex)
        {
            LogClient.Error("Unhandled Exception. {0}", LogClient.GetAllExceptions(ex));

            // Close the application to prevent further problems
            LogClient.Info("### FORCED STOP of {0}, version {1} ###", ProcessExecutable.Name(), ProcessExecutable.AssemblyVersion().ToString());

            // Emergency save of the settings
            SettingsClient.Write();

            Application.Current.Shutdown();
        }
コード例 #5
0
ファイル: App.xaml.cs プロジェクト: Michaelaha/Dopamine
        private void ExecuteEmergencyStop(Exception ex)
        {
            // This is a workaround for a bug in the .Net framework, which randomly causes a System.ArgumentNullException when
            // scrolling through a Virtualizing StackPanel. Scroll to playing song sometimes triggers this bug. We catch the
            // Exception here, and do nothing with it. The application can just proceed. This prevents a complete crash.
            // This might be fixed in .Net 4.5.2. See here: https://connect.microsoft.com/VisualStudio/feedback/details/789438/scrolling-in-virtualized-wpf-treeview-is-very-unstable
            if (ex.GetType().ToString().Equals("System.ArgumentNullException") & ex.Source.ToString().Equals("PresentationCore"))
            {
                if (this.CanLogUnhandledException())
                {
                    LogClient.Warning($"Ignored Unhandled Exception: {ex.Message}");
                }

                return;
            }

            // This is a workaround for an inexplicable issue which occurs on 1 user's computer (as far as I know).
            // Exception "System.ComponentModel.Win32Exception (0x80004005): Access is denied" is thrown when performing
            // function "MS.Win32.UnsafeNativeMethods.GetWindowText(HandleRef hWnd, StringBuilder lpString, Int32 nMaxCount)"
            if (ex.GetType().ToString().Equals("System.ComponentModel.Win32Exception") & ex.Source.ToString().Equals("WindowsBase"))
            {
                if (this.CanLogUnhandledException())
                {
                    LogClient.Warning($"Ignored Unhandled Exception: {ex.Message}");
                }

                return;
            }

            // LogClient.Warning($"Ignored Unhandled Exception: Message=<<<<{ex.Message}>>>>");
            // LogClient.Warning($"Ignored Unhandled Exception: Type=<<<<{ex.GetType().ToString()}>>>>");
            // LogClient.Warning($"Ignored Unhandled Exception: Source=<<<<{ex.Source.ToString()}>>>>");
            // return;

            LogClient.Error("Unhandled Exception. {0}", LogClient.GetAllExceptions(ex));

            // Close the application to prevent further problems
            LogClient.Info("### FORCED STOP of {0}, version {1} ###", ProductInformation.ApplicationName, ProcessExecutable.AssemblyVersion());

            // Stop playing (This avoids remaining processes in Task Manager)
            var playbackService = ServiceLocator.Current.GetInstance <IPlaybackService>();

            playbackService.Stop();

            // Emergency save of the settings
            SettingsClient.Write();

            Current.Shutdown();
        }
コード例 #6
0
        private async void Shell_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            LogClient.Info("### STOPPING {0}, version {1} ###", ProductInformation.ApplicationName, ProcessExecutable.AssemblyVersion().ToString());

            // Prevent saving the size when the window is minimized.
            // When minimized, the actual size is not detected correctly,
            // which causes a too small size to be saved.

            if (!(this.WindowState == WindowState.Minimized))
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    SettingsClient.Set <bool>("General", "IsMaximized", true);
                }
                else
                {
                    SettingsClient.Set <bool>("General", "IsMaximized", false);

                    // TODO: make tis better. Workaround for bug "MainWindow opens with size 0 px"
                    if (this.ActualWidth > 50 & this.ActualHeight > 50)
                    {
                        SettingsClient.Set <int>("General", "Width", (int)this.ActualWidth);
                        SettingsClient.Set <int>("General", "Height", (int)this.ActualHeight);
                    }
                    else
                    {
                        SettingsClient.Set <int>("General", "Width", Defaults.DefaultMainWindowWidth);
                        SettingsClient.Set <int>("General", "Height", Defaults.DefaultMainWindowHeight);
                    }

                    SettingsClient.Set <int>("General", "Top", (int)this.Top);
                    SettingsClient.Set <int>("General", "Left", (int)this.Left);
                }

                // Save the settings immediately
                SettingsClient.Write();
            }

            await this.noteService.CloseAllNoteWindowsAsync();
        }