Esempio n. 1
0
        async Task OnMessageHandlerAsync(
            OnMessageOptions onMessageOptions,
            Func <BrokeredMessage, CancellationToken, Task> callback)
        {
            MessagingEventSource.Log.RegisterOnMessageHandlerStart(this.ClientId, onMessageOptions);

            lock (this.messageReceivePumpSyncLock)
            {
                if (this.receivePump != null)
                {
                    throw new InvalidOperationException(Resources.OnMessageAlreadyCalled);
                }

                this.receivePumpCancellationTokenSource = new CancellationTokenSource();
                this.receivePump = new MessageReceivePump(this, onMessageOptions, callback, this.receivePumpCancellationTokenSource.Token);
            }

            try
            {
                await this.receivePump.StartPumpAsync().ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                MessagingEventSource.Log.RegisterOnMessageHandlerException(this.ClientId, exception);

                this.receivePumpCancellationTokenSource.Cancel();
                this.receivePumpCancellationTokenSource.Dispose();
                this.receivePump = null;
                throw;
            }

            MessagingEventSource.Log.RegisterOnMessageHandlerStop(this.ClientId);
        }
Esempio n. 2
0
 public override Task CloseAsync()
 {
     lock (this.messageReceivePumpSyncLock)
     {
         if (this.receivePump != null)
         {
             this.receivePumpCancellationTokenSource.Cancel();
             this.receivePump = null;
         }
     }
     return(Task.FromResult(0));
 }