【解決方法】アプリケーションがクラッシュしたときにレジストリをクリアしてデバッグを停止する方法(Visual Studio 2019)?

プログラミングQA


In this code it happens that if we close the window with close button, the registry data is cleared. If the EXE crashes, the registry data is not cleared.

Even if the EXE crashes or the application closes or stops debugging, the registry data is cleared. Or when we close the debug from Visual Studio 2019 the registry data should be cleared.

私が試したこと:

C#
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // Dispose the VlcControl when the window is closing
            vlcControl?.Dispose();

            // Clear the registry data
            if (STL.registryy != null)
            {
                // Delete the existing subkey and all its values
                STL.registryy.DeleteSubKeyTree("");
                myUserControl.objectListBox.Items.Clear();

                // Create a new subkey
                STL.registryy = Registry.CurrentUser.CreateSubKey("SOFTWARE\\MyApp");
            }
            else
            {
                // Create a new subkey if it doesn't exist
                STL.registryy = Registry.CurrentUser.CreateSubKey("SOFTWARE\\MyApp");
            }
        }

解決策 1

未処理の例外がキャッチされません。 これらのエラーは検出できますが、.Net Framework と .Net Core では方法が異なります。

.Net Frameworkを想定しています。 これを読む: c# – WPFグローバル例外ハンドラー[^]

コメント

タイトルとURLをコピーしました