Ejemplo n.º 1
0
        public IAsyncResult BeginPoll(string device, string operation, AsyncCallback callback, object state)
        {
            var pollCompletionSource = new PollCompletionSource(device, operation, callback, state);

            NotificationListener.Create().Register(device, operation, pollCompletionSource);
            return(pollCompletionSource.Task);
        }
        public void Register(string device, string operation, PollCompletionSource pollCompletionSource)
        {
            try
            {
                _disposing.EnterReadLock();

                if (_disposed || _cancellationSource.IsCancellationRequested)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }

                _devices.AddOrUpdate(string.Format(FORMAT_KEY_DEVICE, device, operation), pollCompletionSource,
                                     (ekey, epcs) =>
                {
                    epcs.Done();
                    return(pollCompletionSource);
                });
            }
            finally
            {
                _disposing.ExitReadLock();
            }
        }