Exemple #1
0
        static void Main(string[] args)
        {
            //try the five second method with a 6 second timeout
            Console.WriteLine("开始执行方法");
            bool ss = CallWithTimeout(FiveSecondMethod, 5000, 3000);

            Console.WriteLine($"方法执行完成:{ss}");
            //try the five second method with a 4 second timeout
            //this will throw a timeout exception
            //CallWithTimeout(FiveSecondMethod, 4000);
            return;

            MethodInvoker method = () =>
            {
                for (int i = 0; i < 100; i++)
                {
                    Thread.Sleep(20);
                    Console.WriteLine($"当前读到{i},时间是:" + DateTime.Now);
                }
            };

            method.BeginInvoke(null, null);

            Thread.Sleep(1000);
            Console.WriteLine($"1.1开始执行验证:{DateTime.Now}");

            Cats    c = new Cats();
            Mouses  m = new Mouses(c);
            Peoples p = new Peoples(c);

            c.Cry();
            Console.ReadLine();
            //return;

            People.Name = "张三";
            People.Name = "李四";
            Cat    cat    = new Cat();
            Mouse  mouse  = new Mouse(cat);
            People people = new People(cat);

            cat.StartCry();
            Console.ReadLine();
        }
Exemple #2
0
 public Peoples(Cats cat)
 {
     cat.AddObserver(this);
 }
Exemple #3
0
 public Mouses(Cats cat)
 {
     cat.AddObserver(this);
 }