MyProject.Application.SaveMySettingsOnExit should be Properties.Settings.Default.SaveMySettingsOnExit ? but..
"SaveMySettingsOnExit" isn't declared.
Code:
internal sealed class MySettings : ApplicationSettingsBase
{
private static bool addedHandler;
private static object addedHandlerLockObject = RuntimeHelpers.GetObjectValue(new object());
private static MySettings defaultInstance = ((MySettings) SettingsBase.Synchronized(new MySettings()));
[DebuggerNonUserCode, EditorBrowsable(EditorBrowsableState.Advanced)]
private static void AutoSaveSettings(object sender, EventArgs e)
{
if (MyProject.Application.SaveMySettingsOnExit)
{
MySettingsProperty.Settings.Save();
}
}
public static MySettings Default
{
get
{
if (!addedHandler)
{
object addedHandlerLockObject = MySettings.addedHandlerLockObject;
ObjectFlowControl.CheckForSyncLockOnValueType(addedHandlerLockObject);
lock (addedHandlerLockObject)
{
if (!addedHandler)
{
MyProject.Application.Shutdown += new ShutdownEventHandler(MySettings.AutoSaveSettings);
addedHandler = true;
}
}
}
return defaultInstance;
}
}
}
^^ie. 3 private things, and 1 public. Where is the variable for "AutoSaveOnExit"?
you have to declare a local variable in the properties class (Settings.Designer.cs) named AutoSaveOnExit..or um..SaveMySettingsOnExit.
Code:
internal sealed class MySettings : ApplicationSettingsBase
{
public bool SaveMySettingsOnExit = true; // or false I guess
private static bool addedHandler;
private static object addedHandlerLockObject = RuntimeHelpers.GetObjectValue(new object());
private static MySettings defaultInstance = ((MySettings) SettingsBase.Synchronized(new MySettings()));
[DebuggerNonUserCode, EditorBrowsable(EditorBrowsableState.Advanced)]
private static void AutoSaveSettings(object sender, EventArgs e)
{
if (MyProject.Application.SaveMySettingsOnExit)
{
MySettingsProperty.Settings.Save();
}
}
public static MySettings Default
{
get
{
if (!addedHandler)
{
object addedHandlerLockObject = MySettings.addedHandlerLockObject;
ObjectFlowControl.CheckForSyncLockOnValueType(addedHandlerLockObject);
lock (addedHandlerLockObject)
{
if (!addedHandler)
{
MyProject.Application.Shutdown += new ShutdownEventHandler(MySettings.AutoSaveSettings);
addedHandler = true;
}
}
}
return defaultInstance;
}
}
}
and also change MySettingsProperty.Settings.Save to Properties.Settings.Default.Save();
I do mostly vb.net sorry. I might be wrong.
My suggestion -- analyze what settings the program is saving. Are there a lot? Maybe forget about storing them in "Settings" and just create a global variable for each setting, since it's just for you. And erase all the code related to saving settings.
edit: you changed the namespace from "Settings" to "My" so....
MySettingsProperty.Settings.Save == Properties.My.Default.Save();
-- and also, I'm not sure how you modified the "properties" class, because when I create a new project in c# 4.0, my default looks like this (I'm not sure where you got the addHandle / addHandlerLockObject) (?)
Code:
namespace WindowsFormsApplication1.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
public string DoShit = "hellno"; // not default, testing namespace/visibility.
}
}
------
Code:
if (Properties.My.Default.SaveMySettingsOnExit)
{
Properties.My.Default.Save();
}
any of the errors go away? Hopefully only 2 now?
---------- Post added at 02:17 PM ---------- Previous post was at 01:29 PM ----------
or, upload the entire project's source somewhere (remove any lines you deem sensitive of course) (w/ 2 antivirus scans, as dictated by forum rules)
and I'll modify the code and re-upload project.
---------- Post added at 03:13 PM ---------- Previous post was at 02:17 PM ----------
or, if you have TeamViewer (and understand security details involved?), I can connect to you and show you.