public class CategoryAttribute : Attribute
{
private string category;
- private bool IsLocalized = false;
+ private bool IsLocalized;
- static CategoryAttribute action, appearance, behaviour, data, def;
- static CategoryAttribute design, drag_drop, focus, format, key;
- static CategoryAttribute layout, mouse, window_style;
+ static volatile CategoryAttribute action, appearance, behaviour, data, def;
+ static volatile CategoryAttribute design, drag_drop, focus, format, key;
+ static volatile CategoryAttribute layout, mouse, window_style;
+ static object lockobj = new object ();
public CategoryAttribute ()
{
if (action != null)
return action;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (action == null)
action = new CategoryAttribute ("Action");
}
if (appearance != null)
return appearance;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (appearance == null)
appearance = new CategoryAttribute ("Appearance");
}
if (behaviour != null)
return behaviour;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (behaviour == null)
behaviour = new CategoryAttribute ("Behavior");
}
if (data != null)
return data;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (data == null)
data = new CategoryAttribute ("Data");
}
if (def != null)
return def;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (def == null)
def = new CategoryAttribute ();
}
if (design != null)
return design;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (design == null)
design = new CategoryAttribute ("Design");
}
if (drag_drop != null)
return drag_drop;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (drag_drop == null)
drag_drop = new CategoryAttribute ("Drag Drop");
}
if (focus != null)
return focus;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (focus == null)
focus = new CategoryAttribute ("Focus");
}
if (format != null)
return format;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (format == null)
format = new CategoryAttribute ("Format");
}
if (key != null)
return key;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (key == null)
key = new CategoryAttribute ("Key");
}
if (layout != null)
return layout;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (layout == null)
layout = new CategoryAttribute ("Layout");
}
if (mouse != null)
return mouse;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (mouse == null)
mouse = new CategoryAttribute ("Mouse");
}
if (window_style != null)
return window_style;
- lock (typeof (CategoryAttribute)) {
+ lock (lockobj) {
if (window_style == null)
window_style = new CategoryAttribute ("Window Style");
}
{
public sealed class LicenseManager
{
- private static LicenseContext mycontext = null;
- private static object contextLockUser = null;
+ static LicenseContext mycontext;
+ static object contextLockUser;
+
+ static object lockObject = new object ();
private LicenseManager ()
{
public static LicenseContext CurrentContext {
get {
- lock (typeof(LicenseManager)) {
+ lock (lockObject) {
//Tests indicate a System.ComponentModel.Design.RuntimeLicenseContext should be returned.
if (mycontext==null)
mycontext = new Design.RuntimeLicenseContext();
}
}
set {
- lock (typeof(LicenseManager)) {
+ lock (lockObject) {
if (contextLockUser==null) {
mycontext = value;
} else {
object[] args)
{
object newObject = null;
- lock (typeof (LicenseManager)) {
- object lockObject = new object ();
+ lock (lockObject) {
+ object contextUser = new object ();
LicenseContext oldContext = CurrentContext;
CurrentContext = creationContext;
- LockContext (lockObject);
+ LockContext (contextUser);
try {
newObject = Activator.CreateInstance (type, args);
} catch (Reflection.TargetInvocationException exception) {
throw exception.InnerException;
} finally {
- UnlockContext (lockObject);
+ UnlockContext (contextUser);
CurrentContext = oldContext;
}
}
public static void LockContext (object contextUser)
{
- lock (typeof (LicenseManager)) {
+ lock (lockObject) {
contextLockUser = contextUser;
}
}
public static void UnlockContext (object contextUser)
{
- lock (typeof(LicenseManager)) {
+ lock (lockObject) {
//Ignore if we're not locked
if (contextLockUser == null)
return;
{
public sealed class ConfigurationSettings
{
- static IConfigurationSystem config;
-
+ static IConfigurationSystem config = DefaultConfig.GetInstance ();
+ static object lockobj = new object ();
private ConfigurationSettings ()
{
}
public static object GetConfig (string sectionName)
{
- lock (typeof (ConfigurationSettings)) {
- if (config == null)
- config = DefaultConfig.GetInstance ();
- }
-
return config.GetConfig (sectionName);
}
if (newSystem == null)
throw new ArgumentNullException ("newSystem");
- lock (typeof (ConfigurationSettings)) {
- if (config == null)
- config = DefaultConfig.GetInstance ();
-
+ lock (lockobj) {
IConfigurationSystem old = config;
config = newSystem;
return old;
//
class DefaultConfig : IConfigurationSystem
{
- static DefaultConfig instance;
+ static readonly DefaultConfig instance = new DefaultConfig ();
ConfigurationData config;
-
+
private DefaultConfig ()
{
}
public static DefaultConfig GetInstance ()
{
- lock (typeof (DefaultConfig)) {
- if (instance == null)
- instance = new DefaultConfig ();
- }
-
return instance;
}
{
}
+ // Locked by caller
public static bool GetInstance (out IFileWatcher watcher)
{
- lock (typeof (DefaultWatcher)) {
- if (instance != null) {
- watcher = instance;
- return true;
- }
-
- instance = new DefaultWatcher ();
+ if (instance != null) {
watcher = instance;
return true;
}
+
+ instance = new DefaultWatcher ();
+ watcher = instance;
+ return true;
}
public void StartDispatching (FileSystemWatcher fsw)
{
}
+ // Locked by caller
public static bool GetInstance (out IFileWatcher watcher)
{
- lock (typeof (FAMWatcher)) {
- if (failed == true) {
- watcher = null;
- return false;
- }
-
- if (instance != null) {
- watcher = instance;
- return true;
- }
-
- watches = Hashtable.Synchronized (new Hashtable ());
- requests = Hashtable.Synchronized (new Hashtable ());
- if (FAMOpen (out conn) == -1) {
- failed = true;
- watcher = null;
- return false;
- }
+ if (failed == true) {
+ watcher = null;
+ return false;
+ }
- instance = new FAMWatcher ();
+ if (instance != null) {
watcher = instance;
return true;
}
+
+ watches = Hashtable.Synchronized (new Hashtable ());
+ requests = Hashtable.Synchronized (new Hashtable ());
+ if (FAMOpen (out conn) == -1) {
+ failed = true;
+ watcher = null;
+ return false;
+ }
+
+ instance = new FAMWatcher ();
+ watcher = instance;
+ return true;
}
public void StartDispatching (FileSystemWatcher fsw)
bool disposed;
string mangledFilter;
static IFileWatcher watcher;
+ static object lockobj = new object ();
#endregion // Fields
void InitWatcher ()
{
- lock (typeof (FileSystemWatcher)) {
+ lock (lockobj) {
if (watcher != null)
return;
{
}
+ // Locked by caller
public static bool GetInstance (out IFileWatcher watcher)
{
- lock (typeof (KeventWatcher)) {
- if (failed == true) {
- watcher = null;
- return false;
- }
-
- if (instance != null) {
- watcher = instance;
- return true;
- }
-
- watches = Hashtable.Synchronized (new Hashtable ());
- requests = Hashtable.Synchronized (new Hashtable ());
- conn = kqueue();
- if (conn == -1) {
- failed = true;
- watcher = null;
- return false;
- }
+ if (failed == true) {
+ watcher = null;
+ return false;
+ }
- instance = new KeventWatcher ();
+ if (instance != null) {
watcher = instance;
return true;
}
+
+ watches = Hashtable.Synchronized (new Hashtable ());
+ requests = Hashtable.Synchronized (new Hashtable ());
+ conn = kqueue();
+ if (conn == -1) {
+ failed = true;
+ watcher = null;
+ return false;
+ }
+
+ instance = new KeventWatcher ();
+ watcher = instance;
+ return true;
}
public void StartDispatching (FileSystemWatcher fsw)
{
}
+ // Locked by caller
public static bool GetInstance (out IFileWatcher watcher)
{
throw new NotSupportedException ();
class DigestClient : IAuthenticationModule
{
- static Hashtable cache;
-
- public DigestClient () {}
-
+ static readonly Hashtable cache = Hashtable.Synchronized (new Hashtable ());
+
static Hashtable Cache {
get {
- lock (typeof (DigestClient)) {
- if (cache == null) {
- cache = Hashtable.Synchronized (new Hashtable ());
- } else {
- CheckExpired (cache.Count);
- }
-
- return cache;
+ lock (cache.SyncRoot) {
+ CheckExpired (cache.Count);
}
+
+ return cache;
}
}
{\r
public class GlobalProxySelection\r
{\r
- private static IWebProxy proxy;\r
+ volatile static IWebProxy proxy;
+ static readonly object lockobj = new object ();\r
\r
// Constructors\r
public GlobalProxySelection() { }\r
if (proxy != null)\r
return proxy;\r
\r
- lock (typeof (GlobalProxySelection)) {\r
+ lock (lockobj) {\r
if (proxy != null)\r
return proxy;\r
\r
if (value == null)\r
throw new ArgumentNullException ("GlobalProxySelection.Select",\r
"null IWebProxy not allowed. Use GetEmptyWebProxy ()");\r
-\r
- lock (typeof (GlobalProxySelection))\r
- proxy = value; \r
+ proxy = value; \r
}\r
}\r
\r
#endif
public void Test ()
{
- object lockObject = typeof (LicenseManager);
+ object lockObject = new object ();
//**DEFAULT CONTEXT & LicenseUsageMode**
//Get CurrentContext, check default type
AssertEquals ("LicenseManager #1", "System.ComponentModel.Design.RuntimeLicenseContext", LicenseManager.CurrentContext.GetType().ToString());