March 2004
Intermediate to advanced
560 pages
26h 47m
English
using System; using System.Threading; using System.Collections; namespace Samples { public class MonitorSample { private static Hashtable ht = new Hashtable(); public static void Add(object key, object value) { Monitor.Enter(ht); ht.Add(key, value); Thread.Sleep(1000); Monitor.Exit(ht); } public static bool AddNoWait(object key, object value) { if(Monitor.TryEnter(ht)) { ht.Add(key, value); Thread.Sleep(1000); Monitor.Exit(ht); return true; } return false; } public static bool AddWithWaitTime(object key, object value, int waitTime) { if(Monitor.TryEnter(ht, waitTime)) { ht.Add(key, value); Thread.Sleep(1000); Monitor.Exit(ht); return true; } return true; } public static void Display() { Monitor.Enter(ht); IDictionaryEnumerator ide = ...Read now
Unlock full access