Skip to content

Commit e1bfc40

Browse files
sandervandeveldeblackchoey
authored andcommitted
Update Program.cs (#62)
As discussed in microsoft/vscode-azure-iot-edge#503 In the C# module template and the C# function template, a message is constructed: var pipeMessage = new Message(messageBytes); 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. This is also in sync with eg. the https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-csharp-module documentation.
1 parent da7b2d8 commit e1bfc40

File tree

1 file changed

+8
-5
lines changed
  • content/dotnet-template-azure-iot-edge-module/CSharp

1 file changed

+8
-5
lines changed

content/dotnet-template-azure-iot-edge-module/CSharp/Program.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ static async Task<MessageResponse> PipeMessage(Message message, object userConte
7575

7676
if (!string.IsNullOrEmpty(messageString))
7777
{
78-
var pipeMessage = new Message(messageBytes);
79-
foreach (var prop in message.Properties)
78+
using (var pipeMessage = new Message(messageBytes))
8079
{
81-
pipeMessage.Properties.Add(prop.Key, prop.Value);
80+
foreach (var prop in message.Properties)
81+
{
82+
pipeMessage.Properties.Add(prop.Key, prop.Value);
83+
}
84+
await moduleClient.SendEventAsync("output1", pipeMessage);
85+
86+
Console.WriteLine("Received message sent");
8287
}
83-
await moduleClient.SendEventAsync("output1", pipeMessage);
84-
Console.WriteLine("Received message sent");
8588
}
8689
return MessageResponse.Completed;
8790
}

0 commit comments

Comments
 (0)