If invocations are sync (runspace.Invoke()), long scripts could block the IoT listener. Suggestion: Wrap in Task.Run() with CancellationToken from Hub method context. For multi-device fleets, add a semaphore (SemaphoreSlim) to throttle concurrent runspaces (e.g., max 2-3 to avoid OOM).
// Pseudo-patch in Executor
private async Task<ExecutionResult> ExecuteAsync(string script, CancellationToken ct)
{
var semaphore = new SemaphoreSlim(2, 2); // Configurable
await semaphore.WaitAsync(ct);
try
{
using var runspace = RunspaceFactory.CreateRunspace(host);
runspace.Open();
using var pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(script);
var results = await Task.Run(() => pipeline.InvokeAsync(ct), ct);
// Serialize & return
}
finally { semaphore.Release(); }
}
If invocations are sync (
runspace.Invoke()), long scripts could block the IoT listener. Suggestion: Wrap inTask.Run()withCancellationTokenfrom Hub method context. For multi-device fleets, add a semaphore (SemaphoreSlim) to throttle concurrent runspaces (e.g., max 2-3 to avoid OOM).