Skip to content
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

Add System.Threading.PeriodicTimer #53899

Merged
merged 1 commit into from
Jun 24, 2021
Merged

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Jun 8, 2021

Fixes #31525

I still wonder whether IAsyncEnumerable<T> would be a better way to expose this, e.g. a static IAsyncEnumerable<TimeSpan> Periodic(TimeSpan period, CancellationToken cancellationToken = default); as a static method on System.Threading.Timer. One concern there was around what data we'd actually return as the T, but I think an elapsed time since start or something along those lines could be reasonable, even if generally ignored. The other concern was around how one stops the enumeration from outside of the consuming loop (the consuming loop itself can just break out and dispose of the enumerator); I'm personally comfortable using the cancellation token for that purpose, but I know there were concerns about modeling such stopping as an exceptional situation. On the balance, I think that model is cleaner, and I like the idea of adding a new method to Timer rather than increasing the number of timer types we have.

cc: @davidfowl, @terrajobst, @kouvel

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@omariom
Copy link
Contributor

omariom commented Jun 10, 2021

I still wonder whether IAsyncEnumerable would be a better way to expose this, e.g. a static IAsyncEnumerable Periodic(TimeSpan period, CancellationToken cancellationToken = default); as a static method on System.Threading.Timer.

👍

The usage of the new timer is not very different from a while loop with a Task.Delay(..) within. It is not very.. innovative.
Less allocations is not obvious, one would need to read about it in the remarks section of the docs. Also Task.Delays are easier to understand.

@stephentoub stephentoub force-pushed the periodictimer branch 3 times, most recently from 62b0e5d to 9f819ab Compare June 24, 2021 04:27
@stephentoub
Copy link
Member Author

@stephentoub stephentoub added this to the 6.0.0 milestone Jun 24, 2021
@stephentoub stephentoub merged commit 5c2ff17 into dotnet:main Jun 24, 2021
@stephentoub stephentoub deleted the periodictimer branch June 24, 2021 14:24
thaystg added a commit to thaystg/runtime that referenced this pull request Jun 24, 2021
…bugger2

* origin/main: (107 commits)
  Disable MacCatalyst arm64 PR test runs on staging pipeline (dotnet#54678)
  [WASM] Fix async/await in config loading (dotnet#54652)
  Fix for heap_use_after_free flagged by sanitizer (dotnet#54679)
  [wasm] Bump emscripten to 2.0.23 (dotnet#53603)
  Fix compiler references when building inside VS (dotnet#54614)
  process more TLS frames at one when available (dotnet#50815)
  Add PeriodicTimer (dotnet#53899)
  UdpClient with span support (dotnet#53429)
  exclude fragile tests (dotnet#54671)
  get last error before calling a method that might fail as well (dotnet#54667)
  [FileStream] add tests for device and UNC paths (dotnet#54545)
  Fix sporadic double fd close (dotnet#54660)
  Remove Version.Clone from AssemblyName.Clone (dotnet#54621)
  [wasm] Enable fixed libraries tests (dotnet#54641)
  [wasm] Fix blazor/aot builds (dotnet#54651)
  [mono][wasm] Fix compilation error on wasm (dotnet#54659)
  Fix telemetry for Socket connects to Dns endpoints (dotnet#54071)
  [wasm] Build static components; include hot_reload in runtime (dotnet#54568)
  [wasm][debugger] Reuse debugger-agent on wasm debugger (dotnet#52300)
  Put Crossgen2 in sync with dotnet#54235 (dotnet#54438)
  ...
@ghost ghost locked as resolved and limited conversation to collaborators Jul 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API proposal: Modern Timer API
3 participants