We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Refresh Team planning automatically

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


5 Replies

RV Ravikumar Venkatesan Syncfusion Team December 14, 2022 04:13 PM UTC

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



PT Pascal Thomé December 16, 2022 02:31 PM UTC

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



RV Ravikumar Venkatesan Syncfusion Team December 19, 2022 06:44 PM UTC

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.

  • Reproduce the issue in our shared sample, or
  • Issue reproducing sample.


Regards,

Ravikumar Venkatesan


Attachment: syncfusionblazorschedulerefresheventsontimer_1c8774e3.zip


PT Pascal Thomé February 22, 2023 05:04 PM UTC

Hi  Ravikumar ,


Just to inform you that it works now as expected after some old code update.


Regards Pascal



RV Ravikumar Venkatesan Syncfusion Team February 23, 2023 08:10 PM UTC

Pascal,


Thanks for the information that the issue has been resolved. Let us know if you need any other assistance.


Loader.
Live Chat Icon For mobile
Up arrow icon