private void RemoveSubscriptionMessageFromQueue(MessageQueue queue, string type, Uri uri) { subscriptionMessageIds.Write(writer => { var key = new TypeAndUriKey { TypeName = type, Uri = uri }; IList<string> messageIds; if (writer.TryGetValue(key, out messageIds) == false) return; foreach (var msgId in messageIds) { queue.ConsumeMessage(msgId); } writer.Remove(key); }); }