Skip to content

Instantly share code, notes, and snippets.

@QiMata
Created January 7, 2018 14:26
Show Gist options
  • Save QiMata/0cfaae5234adde9b173ccea2f65a9543 to your computer and use it in GitHub Desktop.
Save QiMata/0cfaae5234adde9b173ccea2f65a9543 to your computer and use it in GitHub Desktop.
Function for receiving cloud to device messages
private static async void ReceiveC2dAsync()
{
Console.WriteLine("\nReceiving cloud to device messages from service");
while (true)
{
Message receivedMessage = await deviceClient.ReceiveAsync();
if (receivedMessage == null) continue;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Received message: {0}", Encoding.ASCII.GetString(receivedMessage.GetBytes()));
Console.ResetColor();
await deviceClient.CompleteAsync(receivedMessage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment