{"id":24889109,"url":"https://github.com/timothy-liuxf/frameratetask","last_synced_at":"2025-10-16T06:30:32.788Z","repository":{"id":42716169,"uuid":"355404932","full_name":"Timothy-Liuxf/FrameRateTask","owner":"Timothy-Liuxf","description":"Frame rate stabilizer, a task executor which executes tasks at a stable frame rate. 帧率稳定器——以固定帧率执行任务","archived":false,"fork":false,"pushed_at":"2025-09-30T19:27:41.000Z","size":123,"stargazers_count":10,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-30T21:24:05.337Z","etag":null,"topics":["csharp","framerate","task-scheduler","timer"],"latest_commit_sha":null,"homepage":"https://timothy-liuxf.github.io/FrameRateTask/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Timothy-Liuxf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["Timothy-LiuXuefeng"]}},"created_at":"2021-04-07T03:50:44.000Z","updated_at":"2024-05-31T07:20:16.000Z","dependencies_parsed_at":"2023-02-08T07:30:56.834Z","dependency_job_id":"4613a031-4097-4169-ac42-c1cd46b578e1","html_url":"https://github.com/Timothy-Liuxf/FrameRateTask","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Timothy-Liuxf/FrameRateTask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2FFrameRateTask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2FFrameRateTask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2FFrameRateTask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2FFrameRateTask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Timothy-Liuxf","download_url":"https://codeload.github.com/Timothy-Liuxf/FrameRateTask/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2FFrameRateTask/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279162585,"owners_count":26117240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","framerate","task-scheduler","timer"],"created_at":"2025-02-01T16:17:17.455Z","updated_at":"2025-10-16T06:30:32.533Z","avatar_url":"https://github.com/Timothy-Liuxf.png","language":"C#","funding_links":["https://github.com/sponsors/Timothy-LiuXuefeng"],"categories":[],"sub_categories":[],"readme":"# FrameRateTask\n\n---\n\n## Languages\n\n[English](https://github.com/Timothy-LiuXuefeng/FrameRateTask/blob/master/README.md)  \n[中文（简体）](https://github.com/Timothy-LiuXuefeng/FrameRateTask/blob/master/README.zh-CN.md)\n\n## Introduction\n\n`FrameRateTask`, a frame rate stabilizer, a tool to perform tasks at a stable frame rate.\n\nThis project aims to build an engine that can execute a task repeatedly and at high frequency in a single thread with a precise and stable time interval between every two executions as required. Also, this engine can provide real-time frame rate. This engine can be used to control game frame rate, network communication frame rate, etc.\n\n## Get This Package\n\nTo get this package, please enter the nuget package page: [https://www.nuget.org/packages/FrameRateTask/](https://www.nuget.org/packages/FrameRateTask/)\n\nor use .NET CLI:\n\n```shell\ndotnet add package FrameRateTask\n```\n\n## Author\n\nAutor: Timothy-LiuXuefeng\n\nCopyright (C) 2022 Timothy-LiuXuefeng\n\n## LICENSE\n\n[MIT license](https://github.com/Timothy-Liuxf/FrameRateTask/blob/master/LICENSE.txt)\n\n## Contributing to this repository\n\nPlease read [CONTRIBUTING](https://github.com/Timothy-Liuxf/FrameRateTask/blob/master/CONTRIBUTING.md) carefully before contributing to this repository.\n\n## Interfaces\n\n### CSharp\n\n#### `class FrameRateTaskExecutor\u003cTResult\u003e`\n\n`TResult`: The return value of the task.\n\n+ Constructor:\n\n  + `FrameRateTaskExecutor(Func\u003cbool\u003e loopCondition, Func\u003cbool\u003e loopToDo, long timeInterval, Func\u003cTResult\u003e finallyReturn, long maxTotalDuration = long.MaxValue)`\n\n    If the object is constructed with this constructor, when the `Start` or `TryStart` method of the object is called, the procedure is equivalent to the following code:\n\n    ```c#\n    while (loopCondition \u0026\u0026 time \u003c= maxTotalDuration)\n    {\n     if (!loopToDo()) break;\n     /* Delay until the next frame arrives */\n    }\n    return finallyReturn;\n    ```\n\n    + `loopCondition`: The judgment condition of whether to continue the loop.\n    + `loopToDo`: The loop body. If it returns false, jump out of the loop.\n    + `timeInterval`: The time interval between two executions of the loop body in milliseconds.\n    + `finallyReturn`: Specify the last code to be executed and the return value.\n    + `maxTotalDuration`：The maximum time in milliseconds for the whole task, `long.MaxValue` by default.\n\n  + `FrameRateTaskExecutor(Func\u003cbool\u003e loopCondition, Action loopToDo, long timeInterval, Func\u003cTResult\u003e finallyReturn, long maxTotalDuration = long.MaxValue)`\n\n    The only difference with the previous constructor is that `loopToDo` has no return value so that you cannot jump out of the loop through `loopToDo`.\n\n+ `public void Start()`\n\n  Start the task. If the task has already started, a `Timothy.FrameRateTask.TaskStartedMoreThanOnceException` exception will be thrown. Otherwise, it will start the task and return when the task finishes.\n\n+ `public bool TryStart()`\n\n  Try to start the task. Returns `false` if the task has already started, otherwise it will start the task and return `true` when the task finishes.\n\n+ `public uint FrameRate { get; }`\n\n  The real-time frame rate of the loop body execution, initialized to the expected frame rate, and will be changed during the execution of the task.\n\n+ `public bool Finished { get; }`\n\n  Whether the task has finished.\n\n+ `public bool HasExecuted { get; }`\n\n  Whether the task has been started.\n\n+ `public TResult Result { get; }`\n\n  The return value of the task. A `Timothy.FrameRateTask.TaskNotFinishedException` exception will be thrown if the task has not finished.\n\n+ `public bool AllowTimeExceed { get; init; }`\n\n  Whether to allow the execution timeouts, `true` by default. See the description of `MaxTolerantTimeExceedCount` for more details.\n\n+ `public Action\u003cbool\u003e TimeExceedAction { init; }`\n\n  It will be called after the execution timeouts. See the description of `MaxTolerantTimeExceedCount` for more details.\n\n+ `public ulong MaxTolerantTimeExceedCount { get; init; }`\n\n  The maximum number of consecutive timeouts allowed, `5` by default. Once a loop has timed out, if the number of consecutive timeouts does not exceed `MaxTolerantTimeExceedCount`, `TimeExceedAction` will be called with argument `false`. Otherwise, if `AllowTimeExceed` is set to `false`, a `Timothy.FrameRateTask.TimeExceedException` exception will be thrown; if `AllowTimeExceed` is set to `true`, `TimeExceedAction` will be called with argument `true`, and the incomplete loop will be discarded and the loop count will be reset (see the example `TemporaryCongestion`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothy-liuxf%2Fframeratetask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimothy-liuxf%2Fframeratetask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothy-liuxf%2Fframeratetask/lists"}