Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jsandv opened this issue Apr 22, 2021 · 0 comments · Fixed by #32180
Closed

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

jsandv opened this issue Apr 22, 2021 · 0 comments · Fixed by #32180
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed feature-blazor-desktop This issue is related to Blazor Desktop
Milestone

Comments

@jsandv
Copy link

jsandv commented Apr 22, 2021

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.

@javiercn javiercn added area-blazor Includes: Blazor, Razor Components feature-blazor-desktop This issue is related to Blazor Desktop labels Apr 22, 2021
@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Apr 22, 2021
@mkArtakMSFT mkArtakMSFT modified the milestones: +, 6.0-preview5 Apr 22, 2021
@ghost ghost added Done This issue has been fixed and removed Working labels Apr 27, 2021
@ghost ghost locked as resolved and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed feature-blazor-desktop This issue is related to Blazor Desktop
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants