예제 #1
0
        public Action Add(object sender, Action localDelegate, EventQueueMode mode = EventQueueMode.Synchronous)
        {
            var    key         = new EventHandlerKey(localDelegate, sender);
            Action ourDelegate = () => OnRemoteInvoked(key, new object[0]);

            return(AddInternal <Action>(key, mode, sender, localDelegate, ourDelegate));
        }
예제 #2
0
        // Add custom methods
        public TDelegateType AddInternal <TDelegateType>(
            EventHandlerKey key, EventQueueMode mode, object sender,
            Delegate localDelegate, Delegate ourDelegate)
        {
            Assert.IsNotNull(localDelegate);

            HandlerInfo handler;

            if (_handlers.TryGetValue(key, out handler))
            {
                Assert.IsEqual(mode, handler.Mode, "Cannot use the same event handler method with multiple different EventQueueMode's");

                handler.UsageCount++;
                return((TDelegateType)(object)handler.OurDelegate);
            }

            _handlers.Add(key,
                          new HandlerInfo()
            {
                UsageCount    = 1,
                Key           = key,
                Mode          = mode,
                OurDelegate   = ourDelegate,
                DelegateType  = typeof(TDelegateType),
                LocalDelegate = localDelegate,
            });

            return((TDelegateType)(object)ourDelegate);
        }
예제 #3
0
        public Action <TParam1, TParam2, TParam3> Add <TParam1, TParam2, TParam3>(
            object sender, Action <TParam1, TParam2, TParam3> localDelegate, EventQueueMode mode)
        {
            var key = new EventHandlerKey(localDelegate, sender);
            Action <TParam1, TParam2, TParam3> ourDelegate = (TParam1 param1, TParam2 param2, TParam3 param3) => OnRemoteInvoked(key, new object[] { param1, param2, param3 });

            return(AddInternal <Action <TParam1, TParam2, TParam3> >(key, mode, sender, localDelegate, ourDelegate));
        }
예제 #4
0
        // We could make this public but there's only two queue modes
        // that make sense so it's easier this way
        void TriggerOneOff(Action localDelegate, EventQueueMode mode)
        {
            var key = new EventHandlerKey(localDelegate, null);

            if (_handlers.ContainsKey(key))
            {
                // Already queued
                return;
            }

            _handlers.Add(key,
                          new HandlerInfo()
            {
                UsageCount    = 1,
                Key           = key,
                Mode          = mode,
                IsOneOff      = true,
                DelegateType  = typeof(Action),
                LocalDelegate = localDelegate,
            });

            OnRemoteInvoked(key, new object[0]);
        }
예제 #5
0
 public Action <TParam1, TParam2, TParam3, TParam4> Add <TParam1, TParam2, TParam3, TParam4>(
     Action <TParam1, TParam2, TParam3, TParam4> localDelegate, EventQueueMode mode)
 {
     return(Add <TParam1, TParam2, TParam3, TParam4>(null, localDelegate, mode));
 }
예제 #6
0
 // Zero parameters
 public Action Add(Action localDelegate, EventQueueMode mode = EventQueueMode.Synchronous)
 {
     return(Add(null, localDelegate, mode));
 }