CKY CKY - 1 year ago 87
C# Question

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.

  • Last selected path as

  • Window state as

  • Updated as

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.

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
and then return out of the method.

Answer Source

Catch the exception and call Properties.Settings.Default.Reload() then attempt to save again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download