Skip to content

Commit 77f8406

Browse files
Message class implements Dispose method
The Message class implements the Dispose method. The Message class must follow the dispose pattern to ensure it's disposed in all paths. with 'using()' we can enforce the dispose pattern.
1 parent 3c87405 commit 77f8406

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

articles/iot-edge/tutorial-csharp-module.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,16 @@ Currently, Visual Studio Code can develop C# modules for Linux AMD64 and Linux A
207207
{
208208
Console.WriteLine($"Machine temperature {messageBody.machine.temperature} " +
209209
$"exceeds threshold {temperatureThreshold}");
210-
var filteredMessage = new Message(messageBytes);
211-
foreach (KeyValuePair<string, string> prop in message.Properties)
210+
using (var filteredMessage = new Message(messageBytes))
212211
{
213-
filteredMessage.Properties.Add(prop.Key, prop.Value);
214-
}
212+
foreach (KeyValuePair<string, string> prop in message.Properties)
213+
{
214+
filteredMessage.Properties.Add(prop.Key, prop.Value);
215+
}
215216

216-
filteredMessage.Properties.Add("MessageType", "Alert");
217-
await moduleClient.SendEventAsync("output1", filteredMessage);
217+
filteredMessage.Properties.Add("MessageType", "Alert");
218+
await moduleClient.SendEventAsync("output1", filteredMessage);
219+
}
218220
}
219221

220222
// Indicate that the message treatment is completed.

0 commit comments

Comments
 (0)