You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
variterationCount=10000.0;ProgressTaskpt=null;IProgress<double>progress=newProgress<double>(d =>{// pt.Value = d;// pt.Increment(0); pt.Increment(1);});boolreadyToStart=false;varansiProgressTask= AnsiConsole.Progress().StartAsync(async ctx =>{await Task.Run(()=>{// Add correct reference to ProgressTaskpt= ctx.AddTask("Test IProgress",true, iterationCount);readyToStart=true;while(!ctx.IsFinished){}});});varsomeWork= Task.Run(async()=>{// Wait for ProgressTask to be setwhile(!readyToStart){}for(inti=0;i <= iterationCount;i++){doublepercentage=i/iterationCount*100.0;await Task.Delay(1); progress.Report(percentage);}});await Task.WhenAll(someWork, ansiProgressTask);
The first problem I've experienced was StartAsync blocking, but this problem is already described in #680, so I won't talk about it here further.
The second problem is the need to re-create ProgressTask in AnsiConsole.Progress().StartAsync(...) delegate with ProgressContext.AddTask() method. IMO, it would be great to have an overload for ProgressContext.AddTask() method, that takes ProgressTask as argument and returns void, so we don't need to create a new ProgressTask and wait for it's initialization in working thread (e.g. someWork task here).
And the third problem is that I usually use IProgress.Report() method, which takes percentage, not just ticks, and prints progress to console like this:
that's because I usually don't know which iterationCount will be in my tasks before I run them. But setting ProgressTask.Value property doesn't update the displayed progress. I also tried to call ProgressTask.Increment(0); after changing the Value but it takes no effect. I don't know the best solution for this problem, probably something like INotifyPropertyChanged can be used for Value property, or there's a better, completely different solution?
This discussion was converted from issue #743 on October 01, 2022 14:58.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
After reading corresponding question in discussions and writing my own example I came up with multiple questions, regarding usage of System.IProgress/System.Progress with Spectre.Console.AnsiConsole.Progress.
Here's my code sample:
The first problem I've experienced was
StartAsync
blocking, but this problem is already described in #680, so I won't talk about it here further.The second problem is the need to re-create
ProgressTask
inAnsiConsole.Progress().StartAsync(...)
delegate withProgressContext.AddTask()
method. IMO, it would be great to have an overload forProgressContext.AddTask()
method, that takesProgressTask
as argument and returnsvoid
, so we don't need to create a newProgressTask
and wait for it's initialization in working thread (e.g.someWork
task here).And the third problem is that I usually use
IProgress.Report()
method, which takespercentage
, not just ticks, and prints progress to console like this:that's because I usually don't know which
iterationCount
will be in my tasks before I run them. But settingProgressTask.Value
property doesn't update the displayed progress. I also tried to callProgressTask.Increment(0);
after changing theValue
but it takes no effect. I don't know the best solution for this problem, probably something like INotifyPropertyChanged can be used forValue
property, or there's a better, completely different solution?Beta Was this translation helpful? Give feedback.
All reactions