Beispiel #1
0
        void Function()
        {
            subscriber1   subscriber1 = new subscriber1();
            subscriber2   subscriber2 = new subscriber2();
            WeakReference wr          = new WeakReference(subscriber1);

            Debug.WriteLine("**********Test Async**********");
            Task.Run(() => LLQNotifier.Default.Notify(new Event1()
            {
                Flag = "async flag1"
            }));
            Task.Run(() => LLQNotifier.Default.Notify(new Event2()
            {
                Flag = "async flag2"
            }));
            Task.Run(() => LLQNotifier.Default.Notify(new Event3()
            {
                Flag = "async flag3"
            }));

            Debug.WriteLine("**********Test Normal**********");
            LLQNotifier.Default.Notify(new Event1()
            {
                Flag = "before gc normal flag1"
            });
            LLQNotifier.Default.Notify(new Event2()
            {
                Flag = "before gc normal flag2"
            });

            Debug.WriteLine("**********Test GC**********");
            subscriber1 = null;
            Debug.WriteLine(">>>>>>>>>>Before GC>> subscriber1 is null : " + (subscriber1 == null).ToString());
            GC.Collect();
            Debug.WriteLine(">>>>>>>>>>After GC>>wr is alive : " + wr.IsAlive.ToString());
            LLQNotifier.Default.Notify(new Event1()
            {
                Flag = "after gc normal flag1"
            });
            LLQNotifier.Default.Notify(new Event2()
            {
                Flag = "after gc normal flag2"
            });

            Debug.WriteLine("**********Test Unregister**********");
            subscriber2.Unregister();
            LLQNotifier.Default.Notify(new Event1()
            {
                Flag = "unregister flag1"
            });
            LLQNotifier.Default.Notify(new Event2()
            {
                Flag = "unregister flag2"
            });
        }
Beispiel #2
0
        void Function()
        {
            subscriber1 subscriber1 = new subscriber1();
            subscriber2 subscriber2 = new subscriber2();
            WeakReference wr = new WeakReference(subscriber1);

            Debug.WriteLine("**********Test Async**********");
            Task.Run(() => LLQNotifier.Default.Notify(new Event1() { Flag = "async flag1" }));
            Task.Run(() => LLQNotifier.Default.Notify(new Event2() { Flag = "async flag2" }));
            Task.Run(() => LLQNotifier.Default.Notify(new Event3() { Flag = "async flag3" }));

            Debug.WriteLine("**********Test Normal**********");
            LLQNotifier.Default.Notify(new Event1() { Flag = "before gc normal flag1" });
            LLQNotifier.Default.Notify(new Event2() { Flag = "before gc normal flag2" });

            Debug.WriteLine("**********Test GC**********");
            subscriber1 = null;
            Debug.WriteLine(">>>>>>>>>>Before GC>> subscriber1 is null : " +(subscriber1 == null).ToString());
            GC.Collect();
            Debug.WriteLine(">>>>>>>>>>After GC>>wr is alive : " + wr.IsAlive.ToString());
            LLQNotifier.Default.Notify(new Event1() { Flag = "after gc normal flag1" });
            LLQNotifier.Default.Notify(new Event2() { Flag = "after gc normal flag2" });

            Debug.WriteLine("**********Test Unregister**********");
            subscriber2.Unregister();
            LLQNotifier.Default.Notify(new Event1() { Flag = "unregister flag1" });
            LLQNotifier.Default.Notify(new Event2() { Flag = "unregister flag2" });
        }