private static async Task <T> GetMessageBodyAsync <T>(IReceiverClient client) { string body = null; client.RegisterMessageHandler(async(msg, token) => { Message message = msg; if (message != null) { body = Encoding.UTF8.GetString(message.Body); if (body.Contains("spoiled", StringComparison.OrdinalIgnoreCase)) { await client.DeadLetterAsync(msg.SystemProperties.LockToken); } else { await client.CompleteAsync(msg.SystemProperties.LockToken); } } }, new MessageHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentCalls = 1, AutoComplete = false }); await client.UnregisterMessageHandlerAsync(TimeSpan.FromMilliseconds(2000)); await client.CloseAsync(); if (body != null) { return(JsonSerializer.Deserialize <T>(body)); } return(default);