title: How to call particular function after every two mins In Blazor razor component?
body: <p>I want call particular function after every two mins in blazor. I tried following code </p>
  
  <pre><code>@using System;
  @inherits Microsoft.AspNetCore.Components.OwningComponentBase&lt;TestBlazor.Client.APIGateway&gt;
  
  //Html code to display list.
  
  @code{
      private IEnumerable&lt;TestBlazor.Model.Message&gt; MessagesList;
  
      protected override OnInitialized()
     {
  
       SetTimer();
     }    
  
     private void SetTimer()
     {
        var startTimeSpan = TimeSpan.Zero;
        var periodTimeSpan = TimeSpan.FromMinutes(1);
  
        var timer = new System.Threading.Timer((e) =&gt;
       {
          GetMessage();
       }, null, startTimeSpan, periodTimeSpan);
     } 
  
  
  
     private void GetMessage()
    {
      var filter = new TestBlazor.Model.Filter.MessageFilter()
      {
          Origination = Model.Enums.MessageOrigination.Patient,
          PharmacyId = 1
      };
  
      MessagesList = Service.MessageService.GetFilteredSummaryAsync(filter).Result;
      MessagesList = MessagesList.Select(x =&gt; { x.DateTime = DateTime.Now; return x; }).ToList();
  
      base.InvokeAsync(StateHasChanged);
    }
  }
  </code></pre>
  
  <p>This is working as expected but problem is when I navigate to other component and again come back to this Message component then I am getting following exception</p>
  
  <p><strong>Cannot access a disposed object.
  Object name: 'Messages'</strong>
  where 'Messages' is Razor component name.It will be helpful if anybody could tell me what exactly I am doing wrong? or Is there any other solution for this?  </p>