I'm working on an application with a shared object that is accessed via a singleton. It's working fine on 32-bit however on 64-bit it doesn't appear to be locking properly. In the constructor for my object I have code that checks for some config reg keys and prompts the user if they don't exist. On 32 bit I see the prompt only once as expected however on 64 bit the prompt is being displayed multiple times. My code is below:
private static readonly object padlock = new object();
private static MyClass _instance = null;
public static MyClass Instance
{
get
{
lock (padlock)
{
if (_instance == null)
{
_instance = new MyClass();
}
}
return _instance;
}
}
Any input is greatly appreciated.
Edited To Include Sample Usage:
public OtherObject()
{
InitializeComponent();
MyClass.Instance.OtherObjectOrSomething = this;
this.Load += new System.EventHandler<EventArgs>(OtherObject_Load);
}
Edited Again This is running inside of an Office AddIn. Thus the bitness is determined by the installation of office. I define a parameterless constructor that is private.
Thanks
Removed Slightly Anonimized Constructor