public Item(int num, int num2, IDispatcher consuminingDispatcher, IDispatcher computingDispatcher)
 {
     _num             = num;
     _num2            = num2;
     _numDispatching  = new PropertyDispatching <Item, int>(() => Num, computingDispatcher, consuminingDispatcher);
     _num2Dispatching = new PropertyDispatching <Item, int>(() => Num2, consuminingDispatcher, computingDispatcher);
 }
Beispiel #2
0
            public Item(int num, int num2, OcDispatcher mainOcDispatcher, OcDispatcher backgroundOcDispatcher)
            {
                _num  = num;
                _num2 = num2;
                _numBackgroundToMainDispatching        = new PropertyDispatching <Item, int>(this, nameof(Num), mainOcDispatcher, backgroundOcDispatcher).For(Consumer);
                _num2MainToBackgroundDispatching       = new PropertyDispatching <Item, int>(this, nameof(Num2), backgroundOcDispatcher, mainOcDispatcher).For(Consumer);
                _numBackgroundToMainScalarDispatching  = new Computing <int>(() => Num).ScalarDispatching(mainOcDispatcher, backgroundOcDispatcher).For(Consumer);
                _num2MainToBackgroundScalarDispatching = new Computing <int>(() => Num2).ScalarDispatching(backgroundOcDispatcher, mainOcDispatcher).For(Consumer);

                _numBackgroundToMainScalarDispatching.SetValueRequestHandler = i =>
                {
                    backgroundOcDispatcher.Invoke(() => Num = i);
                };

                _num2MainToBackgroundDispatching.PropertyChanged += (sender, args) =>
                {
                    if (Thread.CurrentThread != backgroundOcDispatcher._thread)
                    {
                        throw new Exception("Wrong thread");
                    }
                };

                _num2MainToBackgroundScalarDispatching.PropertyChanged += (sender, args) =>
                {
                    if (Thread.CurrentThread != backgroundOcDispatcher._thread)
                    {
                        throw new Exception("Wrong thread");
                    }
                };

                _numBackgroundToMainDispatching.PropertyChanged += (sender, args) =>
                {
                    if (Thread.CurrentThread != mainOcDispatcher._thread)
                    {
                        throw new Exception("Wrong thread");
                    }
                };

                _numBackgroundToMainScalarDispatching.PropertyChanged += (sender, args) =>
                {
                    if (Thread.CurrentThread != mainOcDispatcher._thread)
                    {
                        throw new Exception("Wrong thread");
                    }
                };
            }