Skip to content

Commit

Permalink
fix: TheadPoolTimer.CreatePeriodicTimer raises events properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 13, 2021
1 parent ce757a2 commit 33f50d4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.ApplicationModel.Core;
using Windows.System;
using Windows.System.Threading;
using Windows.UI.Core;

namespace Uno.UI.RuntimeTests.Tests.Windows_System
{
[TestClass]
public class Given_ThreadPoolTimer
{
[TestMethod]
public async Task When_Timer()
{
var handlerCount = 0;
var timer = ThreadPoolTimer.CreateTimer(_ => handlerCount++, TimeSpan.FromMilliseconds(100));

await Task.Delay(500);

Assert.AreEqual(handlerCount, 1);

await Task.Delay(500);

Assert.AreEqual(handlerCount, 1);
}

[TestMethod]
public async Task When_PeriodicTimer()
{
var handlerCount = 0;
var timer = ThreadPoolTimer.CreatePeriodicTimer(_ => handlerCount++, TimeSpan.FromMilliseconds(100));

await Task.Delay(500);

Assert.IsTrue(handlerCount > 1);
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.UWP/System.Threading/ThreadPoolTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal ThreadPoolTimer(TimerElapsedHandler handler, TimeSpan? period = null, T

_timer.Change(
period: period ?? global::System.Threading.Timeout.InfiniteTimeSpan,
dueTime: delay ?? global::System.Threading.Timeout.InfiniteTimeSpan
dueTime: delay ?? TimeSpan.Zero
);
}

Expand Down

0 comments on commit 33f50d4

Please sign in to comment.