Hi, I would like to know the best way to refresh events in a read-only scheduler that display a Team's work in progress (blazor server).
The envents are modified by other apps in the same database.
I tried to do a refresh with Javascript's methods setInterval and invokeMethodAsync but this is leading to a memory leak and a server crash.
I am thinking of using RefreshEventsAsync() with a timer but would like to know the best way to do it to avoid memory leak.
Thank you
Hi Pascal,
The best way to avoid memory leaks is to use the RefreshEventsAsync method of the Scheduler. So, we suggest you use the RefreshEventsAsync method as shown in the below code snippet
[Index.razor]
@using System.Threading @using Syncfusion.Blazor.Schedule
<SfSchedule @ref="SchedulerRef" TValue="AppointmentData" Width="100%" Height="650px" @bind-SelectedDate="@CurrentDate" @bind-CurrentView="@CurrentView"> <ScheduleEvents TValue="AppointmentData" Created="OnCreated" Destroyed="OnDestroyed"></ScheduleEvents> </ScheduleEventSettings> </SfSchedule>
@code { SfSchedule<AppointmentData>? SchedulerRef; public Timer? RefreshTimer;
public void OnCreated() { RefreshTimer = new Timer(async _ => { if (SchedulerRef != null) { await SchedulerRef.RefreshEventsAsync(); } }, null, 60000, 60000); }
public void OnDestroyed() { if (RefreshTimer != null) { RefreshTimer.Dispose(); } } } |
Regards,
Ravikumar Venkatesan
Hi Ravikumar,
Thank you for your response.
I have implemented your code but I have an error on await Calendar.RefreshEventsAsync();
System.InvalidOperationException : 'The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.'
I don't see what is wrong with my code.
Do you know what raises this error ?
Thank you
Hi Pascal,
We suspect that the end-to-end sample customization on your sample project may be causing the problem. Please share the below details to proceed further.
Regards,
Ravikumar Venkatesan
Hi Ravikumar ,
Just to inform you that it works now as expected after some old code update.
Regards Pascal
Pascal,
Thanks for the information that the issue has been resolved. Let us know if you need any other assistance.