单独运行.exe时未保存C#设置
我的问题是,当我单独运行.exe文件时,设置不会保存,但当我在Visual Studio中启动应用程序时,它工作正常。设置范围设置为用户。 我使用以下代码将单独运行.exe时未保存C#设置,c#,settings,C#,Settings,我的问题是,当我单独运行.exe文件时,设置不会保存,但当我在Visual Studio中启动应用程序时,它工作正常。设置范围设置为用户。 我使用以下代码将StringCollection保存到设置: internal void SaveFileHistory(string filepath) //saves previously opened file's paths to settings { List<string> paths = OpenFileHistory().
StringCollection
保存到设置:
internal void SaveFileHistory(string filepath) //saves previously opened file's paths to settings
{
List<string> paths = OpenFileHistory().Cast<string>().ToList();
if (!paths.Contains(filepath))
{
if (paths.Count() == 10)
{
paths.RemoveAt(0);
paths.RemoveAll(string.IsNullOrWhiteSpace);
paths.Add(filepath);
}
else
{
paths.Add(filepath);
}
StringCollection collection = new StringCollection();
collection.AddRange(paths.ToArray());
Properties.Settings.Default.OpenedFileHistory = collection;
Properties.Settings.Default.Save();
}
}
internal void SaveFileHistory(string filepath)//将以前打开的文件路径保存到设置
{
列表路径=OpenFileHistory().Cast().ToList();
如果(!path.Contains(filepath))
{
if(path.Count()==10)
{
移除路径(0);
RemoveAll(string.IsNullOrWhiteSpace);
添加(文件路径);
}
其他的
{
添加(文件路径);
}
StringCollection集合=新建StringCollection();
collection.AddRange(path.ToArray());
Properties.Settings.Default.OpenedFileHistory=集合;
Properties.Settings.Default.Save();
}
}
谢谢你的帮助