示例#1
0
        static void Main(string[] args)
        {
            var updater = new NonBlockingSynchronization();
            var person1 = new Person("Ivan", 18);
            var person2 = new Person("Jon", 55);

            var t1 = new Thread(TestUpdater);

            t1.Name = person1.Name;
            var t2 = new Thread(TestUpdater);

            t2.Name = person2.Name;

            var wrap1 = new Wrap
            {
                Updater = updater,
                Person  = person1
            };
            var wrap2 = new Wrap
            {
                Updater = updater,
                Person  = person2
            };

            t1.Start(wrap1);
            t2.Start(wrap2);
            t1.Join();
            t2.Join();

            Console.ReadLine();
        }
示例#2
0
        private static void TestUpdater(object obj)
        {
            NonBlockingSynchronization updater = ((Wrap)obj).Updater;
            Person person = ((Wrap)obj).Person;

            for (int i = 0; i < 10; i++)
            {
                updater.Update(person);
                Console.WriteLine(updater.ToString());
            }
        }