|
using System;
using System.Collections;
namespace StaticAppGlobals
{
public class AppGlobal
{
private static volatile AppGlobal instance = null;
private static object syncRoot = new object();
// make the default constructor private, we never
// explicitly create an instance with "new"
private AppGlobal()
{
}
// public property that gets the single instance of this class.
public static AppGlobal Instance
{
get
{
// only create a new instance if one doesn't already exist.
if (instance == null)
{
// use lock to ensure that only one thread can access
// this block of code at once. You can invoke lock on anything,
// syncRoot is just a convenience object instance.
lock (syncRoot)
{
if (instance == null)
instance = new AppGlobal();
}
}
return instance;
}
}
private static string mySampleProperty = String.Empty;
public static string MySampleProperty
{
get { return mySampleProperty; }
set { mySampleProperty = value; }
}
public static Hashtable MySettings = new Hashtable();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a technical architect/senior software engineer, technical trainer, entrepreneur.
I have worked in several sectors from healthcare, to entertainment and global intelligent traffic systems, using .Net, SQL, NoSQL and some of the latest technologies to deliver quality software systems for clients.
Past tech flavors include C#, WCF, SOA, MVC, MVVM, Silverlight, Assembler, Pascal, VB, Java/J2EE/EJB/JDBC, Perl, NLTK, TSQL, NoSQL, KendoUI, NodeJS, SignalR, Backbone JS, Angular JS, Latest .Net technologies, Amazon AWS...