Hello All,
I am seeing odd behavior when trying to launch an application using an application name stored in Properties.Settings. If I don't re-set the value (to the same value) before using it, the launched application will fail to get the correct location for its application settings. Perhaps showing the code will clear up what I'm saying.
Here is the code that starts the new process. Pretty straight-forward stuff.
private void StartNewApplication()
{
Process mainAppProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Properties.Settings.Default.TheApplicationPath;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
mainAppProcess.StartInfo = startInfo;
mainAppProcess.Start();
mainAppProcess.WaitForExit();
}
I have another function that simply sets the Setting by browsing for the file in a standard OpenFileDialog. I won't bother showing that here, except for the snippet:
if (fileDialog.ShowDialog().Value == true)
{
Properties.Settings.Default.TheApplicationPath = fileDialog.FileName;
Properties.Settings.Default.Save();
}
The code that was failing (which I have no control over) is something like:
private static string GetConfigFolder()
{
string configFolder = ConfigurationManager.AppSettings.Get("ConfigFolder");
configFolder = Path.GetFullPath(configFolder);
return string.IsNullOrEmpty(configFolder) ? Environment.CurrentDirectory : configFolder;
}
Since the AppSettings value is always coming back ".", the Path.GetFullPath call returns the current directory. If I don't re-set the Properties.Setting value, it is the path of the program that starts the application; if I re-set the Setting, it is the path of the application that has been launched.
Any ideas?
Thanks, WtS