public void Register(CustomTimer timer)
 {
     if (timer == null)
         throw new ArgumentNullException();
     Console.WriteLine("MicrowaveAlarm is now registered");
     timer.TimeIsUp += MicrowaveAlarmMsg;
 }
 public void Unregister(CustomTimer timer)
 {
     if (timer==null)
         throw new ArgumentNullException();
     Console.WriteLine("HandWatchAlarm is now unregistered");
     timer.TimeIsUp -= AlarmMsg;
 }
 static void Main(string[] args)
 {
     CustomTimer customTimer=new CustomTimer();
     MicrowaveAlarm microwaveAlarm=new MicrowaveAlarm(customTimer);
     HandWatchAlarm handWatchAlarm=new HandWatchAlarm(customTimer);
     customTimer.StartTimer(5);
     Thread.Sleep(5500);
     microwaveAlarm.Unregister(customTimer);
     customTimer.StartTimer(3);
     Thread.Sleep(3500);
     handWatchAlarm.Unregister(customTimer);
     Console.ReadKey();
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Random random = new Random();

            CustomTimer timer = new CustomTimer();

            Console.WriteLine("ICacheManager<int, int>");
            for (int j = 0; j < 10; ++j)
            {
                ICacheManager<int, int> cacheManager = new CacheManager<int, int>();

                timer.Start();

                // No concurrency insertions
                for (int i = 0; i < 1000000; ++i)
                {
                    cacheManager.AddEntry(random.Next(int.MaxValue), i);
                }

                timer.StopAndReport();

                GC.Collect(2);
                GC.WaitForFullGCComplete();
            }
            Console.WriteLine("");

            Console.WriteLine("ICacheManager<int, string>");
            for (int j = 0; j < 10; ++j)
            {
                ICacheManager<int, string> cacheManager = new CacheManager<int, string>();

                timer.Start();

                // No concurrency insertions
                for (int i = 0; i < 1000000; ++i)
                {
                    cacheManager.AddEntry(random.Next(int.MaxValue), "dummy string " + i);
                }

                timer.StopAndReport();

                GC.Collect(2);
                GC.WaitForFullGCComplete();
            }
            Console.WriteLine("");

            Console.WriteLine("ICacheManager<int, string, int>");
            for (int j = 0; j < 10; ++j)
            {
                ICacheManager<int, string, int> cacheManager = new CacheManager<int, string, int>();

                timer.Start();

                // No concurrency insertions
                for (int i = 0; i < 1000000; ++i)
                {
                    cacheManager.AddEntry(random.Next(int.MaxValue), "dummy string " + i);
                }

                timer.StopAndReport();

                GC.Collect(2);
                GC.WaitForFullGCComplete();
            }
            Console.WriteLine("");

            Console.ReadLine();
        }