예제 #1
0
		private WeakEventSource(SimpleImmutableSet<IMakeEventCallbacks> callbacks)
		{
			if (callbacks == null)
				throw new ArgumentNullException("callbacks");
			if (callbacks.Any(c => c == null))
				throw new ArgumentException("Null reference encountered in callbacks set");

			_callbacks = callbacks;
		}
예제 #2
0
		public void Fire(object sender, TEventArgs e)
		{
			// Note: Not checking for null "sender" or "e" references here since any contracts an event may have that these
			// should or should not support nulls are not for us to deal with here
			
			var haveAnyCallbacksExpired = false;
			var callbacksCopy = _callbacks;
			foreach (var callback in callbacksCopy)
			{
				var didCallbackExecute = callback.ExecuteCallbackIfTargetStillAlive(sender, e);
				if (!didCallbackExecute)
					haveAnyCallbacksExpired = true;
			}

			if (haveAnyCallbacksExpired)
			{
				lock (_callbacks)
				{
					_callbacks = _callbacks.RemoveWhere(c => !c.IsTargetStillAlive);
				}
			}
		}