private void OptimisticQueuing(DroneEvent droneEvent, CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { var eventQueue = _eventQueue; var original = Interlocked.CompareExchange( ref _eventQueue, eventQueue.Enqueue(droneEvent), eventQueue); if (object.ReferenceEquals(eventQueue, original)) { return; } } }
protected void OnNewEvent(DroneEvent data) { NewEvent?.Invoke(this, data); }