私は Visual Studio の初心者で、app.config ファイルを扱っています。ちょっとしたヒントをお聞きしたいのですが、Windows フォームを使用して app.config ファイルで値キーを数回更新する最良の方法は何ですか。これまでのところ、私はこれを試しました:
Form1 が閉じられる直前に、次のコードで値を更新します。
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(Application.StartupPath & "\MyProyect.exe")
Dim aps As AppSettingsSection = config.AppSettings
aps.Settings.Item("SomeKey").Value = 5 'just an example
config.Save(ConfigurationSaveMode.Modified)
次に、次のフォームが次のように開かれます。
Form1.Hide()
Form2.Show()
しかし、新しい Form2 の同じキーに値を再度保存しようとすると、プログラムがフリーズしてエラーが発生します。
構成ファイルが別のプログラムによって変更されています。 (C:\Users\RH\Documents\Visual Studio 2010\Projects\MyProyect\MyProyect\bin\Debug\MyProyect.exe.config)
本当に解決策を探していますが、この種の問題を抱えているのは私だけのようです。言ってしまえば、ただの初心者です。アドバイスをお願いできますか?