Cannot get progressbar to work
Hi
I have tried a multitude of different pieces of code to get the progressbar to update but none of them works.
Some of them were "working examples" from this forum or your homepage but the progressbar will not update at all.
My code looks like this (only the important parts):
<div>
2. <Button style="margin-top:20px" @onclick="() => onAddClick()">Create Embeddings</Button>
</div>
<div style="margin-top:25px">
<SfUploader AutoUpload="false" AllowMultiple=false >
<UploaderEvents ValueChange="OnChange"></UploaderEvents>
</SfUploader>
</div>
</div>
<div style="height:50px"></div>
<SfProgressBar @ref="prbar" Type="ProgressType.Linear" Minimum="0" Maximum="100" Value="@value" TrackThickness="8" ProgressThickness="8">
</SfProgressBar>
<h3>Result Top 10</h3>
@code {
public List<string> productImages = new List<string>();
private string model = "";
public SfProgressBar prbar;
double value = 1;
public double CompletionPercentage { get; set; }
public List<string> modelNames = new List<string> { "resnet50-v1-12-int8.onnx", "efficientnet-lite4-11-int8.onnx", "mobilenetv2-7.onnx" };
protected override async Task OnInitializedAsync()
{
productImages = await restService.ListImagesInStorage(Constants.ProductImagesContainer);
}
private void onAddClick()
{
int count = 0;
var client = new HttpClient();
vectorModelTesterService.DeleteAllImages();
foreach(string image in productImages)
{
var response = client.GetAsync(image).Result;
byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
if(model != "")
vectorModelTesterService.EmbedImageAsVector(bytes, Utilities.GetFileName(image), model);
count = count + 1;
this.value = count;
InvokeAsync(StateHasChanged);
}
}
Hi Sune Sorgenfrei,
We have analyzed your query, "The progress bar value is not updating when the button is clicked". We used mock image URLs to retrieve the progress value and tested it. The progress bar is updated accordingly, as shown in the GIF below. The progress bar displays the last value of the iteration. Please find the sample code below, which was used for testing. If this does not meet your requirements, please make modifications to the attached sample and let us know.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Progress1460059907.zip
GIF Image:
Kindly revert us if you have any concerns.
Regards,
Gopalakrishnan Veeraraghavan
Hi Sune Sorgenfrei,
We have attached the GIF image. Please find the GIF image for your reference.
Regards,
Gopalakrishnan Veeraraghavan
Attachment: progressbar_a694a628.zip
Hi
I have tried to implement your code which basically is the same as I already had, but it does not work.´
The reason there is some progress in the bar is because the value variable starts with 1, but it does not move when it is incremented.
The progressbar is not updated at all it just stays the same as in your image eventhough the counter variable is incremented. So unfortunately this does not work.
Best Regards,
Sune
Hi
Just disregard my latest comment. It works now as expected and it was my bad somehow the counter variable was reset to 0 in my loop and therefore the progressbar did not move. :-)
Best Regards,
Sune
Hi Sune Sorgenfrei,
Most welcome. Please get back to us if you need any further assistance. We are always happy in assisting you.
Regards,
Gopalakrishnan Veeraraghavan
- 5 Replies
- 2 Participants
-
SS Sune Sorgenfrei
- Aug 31, 2023 01:04 PM UTC
- Sep 4, 2023 05:53 AM UTC