Click here to Skip to main content
15,886,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have two applications say "application 1" and "application 2", now my "application 1" continuously read value from config file that is used or defined in it. "application 2" update above config file declare in "application 1".

I have used delegate and event structure where once current value get change subscriber get notification in "application 1"

My main code is given bellow
C#
public class Configcheck
    {
        public bool ConfigValue;
        // the delegate the subscribers must implement
        public delegate void ConfigChangeEventHandler(object configcheck,
                        ConfigInfoEventArgs ValueInformation);

        public event ConfigChangeEventHandler ConfigChange;

        public void Run()
        {
            for (; ; )
            {
                // sleep 10 milliseconds
                Thread.Sleep(100);

                // get the current AppSetting value of "CHKEBL"
              
                bool read_configvalue = Convert.ToBoolean(CryptorEngine.Decrypt(ConfigurationManager.AppSettings["CHKEBL"].ToString(), true));
                // if the Value has changed
                // notify the subscribers
                if (read_configvalue != ConfigValue)
                {
                    // create the ConfigInfoEventArgs object
                    // to pass to the subscriber
                    ConfigInfoEventArgs configInformation =
                        new ConfigInfoEventArgs(read_configvalue);

                    // if anyone has subscribed, notify them
                    if (ConfigChange != null)
                    {
                        ConfigChange(this, configInformation);
                    }
                }

                // update the state
                this.ConfigValue = read_configvalue;

            }
        }


    }


My problem is that when "application 2" changes the app.config file defined in "application 1", the above for loop does not read the updated value. I need to restart the "application 1" to read the updated value.

so I need "application 1" should read updated value as soon as it get changed by the "application 2". please note that "application 1" and "application 2" run simultaneously.

Value that I want to read from the app.config file is as given bellow.

<appsettings>
    <add key="CHKEBL" value="true" />
  </appsettings>


Application 2 changes above value to true or false so accordingly that updated value of config file my application 1 should read in real time.
Thanks in Advance.
Posted
Updated 7-Jun-14 4:03am
v4

Try the method suggested at Update app.config key value at run time in WPF[^].
 
Share this answer
 
it does not read from the physical file each time you ask for a value. you need to refresh the section and read the value as below
C#
ConfigurationManager.RefreshSection("appSettings");
bool read_configvalue = Convert.ToBoolean(CryptorEngine.Decrypt(ConfigurationManager.AppSettings["CHKEBL"].ToString(), true));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900