/// <summary> /// Purges the specified queue. Purge is done by deleting and re-creating the queue - fastest way to purge. /// </summary> /// <param name="manager">The manager to extend.</param> /// <param name="queueName">Name of the queue to purge.</param> /// <returns>Task.</returns> /// <exception cref="ArgumentException">Cannot purge queue as it has been defined as a topic - queueName</exception> public static async Task PurgeQueue(this ManagementClient manager, string queueName) { try { // Delete the queue. await manager.DeleteQueueAsync(queueName); // Then recreate it. manager.CreateQueueIfNotExists(queueName); } catch (Exception) { try { // Check to see if a topic exists already with the name of the queue you are trying to create. if (await manager.GetTopicAsync(queueName) != null) { throw new ArgumentException($"Cannot purge queue as it has been defined as a topic: {queueName}", "queueName"); } } catch (ArgumentException) { throw; } catch (Exception) { throw; } } }