Skip to content

Timer not supported in WPF for Blazor .net6 preview 3 #32057

@jsandv

Description

@jsandv

Component timers do not work in Blazor Desktop on WPF .net6 Preview 3.

Repro is to clone the current demo-app (https://github.com/danroth27/BlazorDesktopWPF) and add a timer in the counter.razor.

@namespace BlazorDesktopWPF
@using Microsoft.AspNetCore.Components.Web
@using System.Timers
<h1>Counter</h1>

<p>The current count is: @currentCount</p>
<button @onclick="IncrementCount">Count</button>

@code {
	int currentCount = 1;

	void IncrementCount()
	{
      currentCount++;
	}
	Timer _timer;
	protected override void OnAfterRender(bool firstRender)
	{
	  if (firstRender)
	  {
		  _timer = new Timer();
		  _timer.Elapsed += callback;
		  _timer.Interval = 1000;
		  _timer.Start();

	  }
	}
	public async void callback(object sender, ElapsedEventArgs e)
	{
	  currentCount++;
	  await InvokeAsync(StateHasChanged);
	}
}	

Exception:
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
InvalidOperationException: Received unexpected acknowledgement for render batch 4 (next batch should be 3)
I tried System.Threading timer and SystemTimers timer.

Metadata

Metadata

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-desktopThis issue is related to Blazor Desktop

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions