/// <summary> /// This method causes the communication listener to close. Close is a terminal state and /// this method allows the communication listener to transition to this state in a /// graceful manner. /// </summary> /// <param name="cancellationToken">Cancellation token</param> /// <returns> /// A <see cref="T:System.Threading.Tasks.Task">Task</see> that represents outstanding operation. /// </returns> public Task CloseAsync(CancellationToken cancellationToken) { WriteLog("Service Bus Communication Listnener closing"); _stopProcessingMessageTokenSource.Cancel(); //Wait for Message processing to complete.. ProcessingMessage.WaitOne(); ProcessingMessage.Dispose(); return(CloseImplAsync(cancellationToken)); }