Introduction
when we developWindowsform Application, we will definitely useApp.the. We can add, modify and delete keys/The value pair manages user preferences. Here, it will save you time.
Demonstrate
Here's a simple Windows Forms application to show how to add a key pair to the App. config file. I built the Windows Forms application inside of Visual Studio 2015.
Using System;Using System.Collections.Generic;Using System.ComponentModel;Using System.Data;Using System.Drawing;Using System.Linq;Using System.Text;Using System.Threading.Tasks;Using System.Windows.Forms;Using System.Configuration;Namespace appconfig{PublicPartialClass Form1:form {Public Form1 () {InitializeComponent ();}//Display current value of Setting1 variablePrivatevoid Button2_Click (Object sender, EventArgs e) {//Clear first Label1. Text =""; Displayconfig (); }Privatevoid Displayconfig () {foreachString keyIn configurationmanager.appsettings) {StringValue = Configurationmanager.appsettings[key]; Label1. Text = Label1. Text +" + key + ": "+ value;}} //display current content in app. Config appSettings section private void button1_click (object sender , EventArgs e) {Configuration config = configurationmanager.openexeconfiguration (configurationuserlevel.none); config . APPSETTINGS.SETTINGS.ADD ("modificationtime", DateTime.Now.ToLongTimeString () + " "); Config. Save (configurationsavemode.modified); Configurationmanager.refreshsection ("appSettings"); }}}
Problem
Visual Studio2015, press F5 to run the application. Press the button to add the time to App. Config, and then click the Show button in the current value of the app. Config file:
We can see that the modification time is added to app. Config. Now, we go to the Bin folder for this item and find in App. Config. Open it in Notepad and you will find that the modification time does not exist. The problem here is this: we see this time added to App. Config, but when we open the App. Config file and the key/value pair does not exist.
What happened?
Reply
It is related to the visual Studio 2015 debugging process. When we press?? F5 key and starts the debugging process, Visual Studio creates its own host process. Inside the project Bin/debug folder, you will see the projectname.vshost and ProjectName.vshost.exe XML files. When you run the visual Studio IDE in the application, modify the time key/value pair into the ProjectName.vshost.exe XML file. When you stop debugging, the cache is freed, and the Modify time key/value pair is refreshed from the XML file. So you won't see any changes to this XML file.
Also note that during the commissioning process, the projectName.exe.config is never used. So, if we open the ProjectName.exe.config file, we will not see any changes.
Two solutions:
Workaround one: Start the command line prompt and go to the Bin\ Debug folder. Run the demo application from there. You will see the modified time in the appsettings section of App. Config.
Workaround Two: Select the project's property page; Select the Debug tab, go to the bottom area "Enable Debugger", uncheck "Enable Visual Studio host Process" for the following:
Hopefully this will prompt some time to save your future. If you have any comments and feedback, please let me know.
Original link Http://www.codeproject.com/Tips/1086805/Basics-on-debugging-App-config-for-Windows-Form-Ap#_articleTop
Windows application based on debug mode app. config settings