Ejemplo n.º 1
0
        private async Task <IXBeeEvent> WaitEventAsync(Type eventClass, CancellationToken cancellationToken)
        {
            IXBeeEventListenerProperties xbeeEventListener = new XBeeEventListener(eventClass);

            // Register a listener
            AddEventListener(xbeeEventListener);

            // Wait for the event
            while (!_mainCancellationToken.IsCancellationRequested &&
                   !cancellationToken.IsCancellationRequested &&
                   !xbeeEventListener.Complete)
            {
                // wait until transaction is complete
                await Task.Delay(5);
            }

            // Remove the listener
            RemoveEventListener(xbeeEventListener);
            return(xbeeEventListener.ReceivedEvent);
        }
Ejemplo n.º 2
0
        private async Task <IXBeeEvent> WaitEventAsync(Type eventClass)
        {
            IXBeeEventListenerProperties xbeeEventListener = new XBeeEventListener(eventClass);

            await _taskFactory.StartNew(() =>
            {
                // Register a listener
                AddEventListener(xbeeEventListener);

                // Wait for the event
                lock (xbeeEventListener)
                {
                    while (!xbeeEventListener.Complete)
                    {
                        // wait until transaction is complete
                    }
                }

                // Remove the listener
                RemoveEventListener(xbeeEventListener);
            });

            return(xbeeEventListener.ReceivedEvent);
        }