title: Blazor Server Periodic update of images using a timer
body: <p>Sorry for the rudimentary question.</p>
  <p>An image is pasted and displayed on a web page created with Blazor Server.</p>
  <p>I would like to update this displayed image on a regular basis. (For example, updated every second)</p>
  <p>This image is stored in the location wwwroot / imageFiles with the name PreviewImage.bmp.</p>
  <p>Specifically, I want to switch the image displayed on the web page to the replaced image when PreviewImage.bmp under this wwwroot / imageFiles is replaced.</p>
  <p>For example, when I change PreviewImage.bmp that shows a dog to PreviewImage.bmp that shows a cat, I want to switch the image displayed on the web page.</p>
  <p>I wondered if I could update the image using StateHasChanged (); with a timer, but this didn't work.</p>
  <pre><code>&lt;img src=&quot;@previewImg&quot; /&gt;
  
  @code{
      
      private string previewImg = string.Empty;
      private Timer timer = new(1000);
  
      protected override void OnInitialized()
      {
          previewImg = @&quot;imageFiles/PreviewImage.bmp&quot;;
  
          timer.Elapsed += (sender, eventArgs) =&gt; OnTimerCallback();
          timer.AutoReset = true;
          timer.Start();            
      }
  
      private void OnTimerCallback()
      {    
          _ = InvokeAsync(() =&gt;
         {    
           previewImg = @&quot;imageFiles/PreviewImage.bmp&quot;;
           StateHasChanged();
         });
      }
   }
  </code></pre>
  <p>However, if you reload the entire page with the F5 key, the image will be updated.</p>
  <p>Is there a way to achieve this image update?</p>
  <p>I'm sorry that the content is very difficult to understand.</p>
  <p>Thank you for your advice.</p>