[英]What is the best way to handle Multi-instance Properties.Settings.Default.Save()
I have a C# Winforms application that uses app.config to save 3 simple settings. 我有一个使用app.config保存3个简单设置的C#Winforms应用程序。
string
string
bool
bool
bool
bool
This is a multi-instance application and when a user has more then one instance open and closes the application group, they are met with 这是一个多实例应用程序,当用户打开一个以上实例并关闭该应用程序组时,会遇到
System.Configuration.ConfigurationErrorsException: Failed to save settings: The configuration file has been changed by another program.
System.Configuration.ConfigurationErrorsException:无法保存设置:配置文件已被另一个程序更改。
What is the best way to manage this? 最好的管理方式是什么?
I know I can catch the error and return out of application-exit method but this seems improper. 我知道我可以捕获错误并退出应用程序退出方法,但这似乎是不正确的。 It would seem to me that there should be a way to check if another instance is working in the file before calling
Properties.Settings.Default.Save();
在我看来,应该有一种方法可以在调用
Properties.Settings.Default.Save();
之前检查文件中是否有另一个实例Properties.Settings.Default.Save();
and then return out of the method. 然后返回该方法。
捕获异常并调用Properties.Settings.Default.Reload()
然后尝试再次保存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.