Home

How to update Util.Progress from separate thread?

edited May 22

I'm invoking some command line processes asynchronously using the CliWrap library. As it's running, I want to try to keep track of the relative progress and use Util.Progress to do that. However it's not working for me, I'm assuming because the thread I'm getting updates on is different from the main one. The actual progress I see in LINQPad doesn't update like I would expect.

How can I get this updated? Is there an "Invoke()" method that I can call?

Util.Progress = 0;
await Cli.Wrap(@"path to some process")
    .WithArguments([my arguments])
    .WithStandardOutputPipe(PipeTarget.ToDelegate(ProcessStdout)) // calls delegate for every line written to stdout
    .ExecuteAsync(QueryCancelToken);
Util.Progress = null;

void ProcessStdout(string line)
{
    // parse line and determine if any progress has been made
    if (/* not a progress line */)
    {
        line.Dump(); // output like normal
        return;
    }
    // calculate the progress
    var progress = /* some number between 0 and 100 */;
    Util.Progress = progress; // doesn't actually update the progress
}

Comments

Sign In or Register to comment.