How to change Value based on Timed event

Hi.

I want to change the Progressbar Value based on a timed event. 

Markup:
 <SfProgressBar @ref="prbar" Type="ProgressType.Linear" Minimum="0" Maximum="100" Value="0"
                   TrackThickness="8" ProgressThickness="8">
       
    </SfProgressBar>

@Code:
SfProgressBar prbar;

Timed Event:
    private void OnTimedEvent(Object source, ElapsedEventArgs e)
    {
     
        var responseInfo=new ExperimentExecuterFunctions().GetState();
        prbar.Value = responseInfo.Progress;
      
        InvokeAsync(StateHasChanged);
        

        
    }




1 Reply

BP Baby Palanidurai Syncfusion Team March 26, 2020 07:15 AM UTC

Hi Angelo, 
 
Greetings from Syncfusion. 
 
We have analyzed your query. We have prepared a simple sample with timer. In that, we have changed the progress bar value in the timer event.  
Code snippet: 
<SfButton @ref="button" Content="Start" @onclick="@onChange"></SfButton> 
<SfProgressBar @ref="prbar" Type="ProgressType.Linear" Minimum="0" Maximum="100" Value="@value" TrackThickness="8" ProgressThickness="8"> 
</SfProgressBar> 
 
@code { 
    public SfProgressBar prbar; 
    public SfButton button; 
    double value = 1; 
    Timer aTimer = new Timer(); 
 
    void onChange(MouseEventArgs args) 
    { 
        SetTimer(); 
    } 
    void SetTimer() 
    { 
        aTimer.Interval = 2000; 
        aTimer.Elapsed += OnTimedEvent; 
        aTimer.Enabled = true; 
        aTimer.Start(); 
    } 
 
    void OnTimedEvent(Object source, ElapsedEventArgs e) 
    { 
        if (this.value < 100) 
        { 
            this.value = this.value + 10; 
        } else 
        { 
            this.value = 0; 
        } 
        InvokeAsync(StateHasChanged); 
    } 
} 
 
 
 
 
Kindly revert us, if you have any concerns. 
 
Regards, 
Baby. 
 


Loader.
Up arrow icon