Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            db1 = new DBWrapper1("DB1");

            Thread newThread = new Thread(ThreadProc);

            newThread.Start();

            Thread.Sleep(500);
            Console.WriteLine("Acquiring lock");
            Monitor.Enter(db1);

            //
            // Do some work
            //

            Console.WriteLine("Releasing lock");
            Monitor.Exit(db1);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            db1 = new DBWrapper1("DBCon1");
            db2 = new DBWrapper2("DBCon2");

            Thread newThread = new Thread(ThreadProc);

            newThread.Start();

            Thread.Sleep(2000);
            lock (db2)
            {
                Console.WriteLine("Updating DB2");
                Thread.Sleep(2000);
                lock (db1)
                {
                    Console.WriteLine("Updating DB1");
                }
            }
        }