Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit d4443bb

Browse files
peterfeltshathind-ms
authored andcommitted
Fixing a bug where telemetry wasn't sent for some devices. (#306)
1 parent 5a7875e commit d4443bb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

SimulationAgent/Agent.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,20 @@ private void TryToStartThreads()
399399
// Telemetry
400400
try
401401
{
402-
var count = this.appConcurrencyConfig.TelemetryThreads;
402+
var telemetryThreadCount = this.appConcurrencyConfig.TelemetryThreads;
403403

404-
this.devicesTelemetryThreads = new Thread[count];
404+
this.devicesTelemetryThreads = new Thread[telemetryThreadCount];
405405
this.devicesTelemetryTasks = new List<IDeviceTelemetryTask>();
406-
for (int i = 0; i < count; i++)
406+
for (int i = 0; i < telemetryThreadCount; i++)
407407
{
408408
var task = this.factory.Resolve<IDeviceTelemetryTask>();
409409
this.devicesTelemetryTasks.Add(task);
410410

411+
// Thread position must be calculated outside of the thread-execution lambda. Otherwise,
412+
// the thread index passed to the execution method will be off by one.
413+
var telemetryThreadPosition = i + 1;
411414
this.devicesTelemetryThreads[i] = new Thread(
412-
() => task.RunAsync(this.deviceTelemetryActors, i + 1, count, this.runningToken.Token));
415+
() => task.RunAsync(this.deviceTelemetryActors, telemetryThreadPosition, telemetryThreadCount, this.runningToken.Token));
413416
this.devicesTelemetryThreads[i].Start();
414417
}
415418
}

0 commit comments

Comments
 (0)