Using Terminal.Gui I'm trying to set a TextView's text from a asynchronous function, I can do it in C# just fine from a task but not from a Powershell Job, there might be a PS concept I'm missing here.
TextView tv = new TextView();
Task.Run(() =>
{
Thread.Sleep(5000);
tv.Text = "task";
Application.DoEvents();
});
I've tried running a job script block
Start-Job -ScriptBlock { $textView.Text = "task" }
And also tried to invoke it from the MainLoop, not sure I'm doing this properly but it looks like this
function FromJob {
param (
[Terminal.Gui.TextView] $tv
)
$delegate = [System.Action]{
$tv.Text = "Delegate"
}
[Terminal.Gui.Application]::MainLoop.Invoke($delegate)
}
Start-Job -ScriptBlock { FromJob } -ArgumentList @($textView)