# Precision Timer.NET
[![Nuget](https://img.shields.io/nuget/v/PrecisionTimer.NET)](https://www.nuget.org/packages/PrecisionTimer.NET/)
This timer is as precise as the platform you are running it on down to 1 millisecond.
PrecisionTimer.NET won't randomly dispose itself, You don't need to keep a special reference to it.
If you intend to use a lot of timers, consider using [Timer Sink.NET](https://github.com/HypsyNZ/Timer-Sink.NET)
# Usage
Using Precision Timer is as simple as using any other Windows Timer.
```cs
public readonly PrecisionTimer MyTimer = new();
MyTimer.SetInterval(SomeAction, Interval);
```
If you use `SetInterval` to set `Action` and provide `Interval` the timer will automatically start with the default settings
If you don't want the timer to start automatically then use the following
```cs
MyTimer.SetInterval(SomeAction, Interval, false);
```
## Basics
Start the Timer
```cs
MyTimer.Start();
```
Check if the Timer is Running
```cs
MyTimer.IsRunning();
```
Stop the Timer
```cs
MyTimer.Stop();
```
Dispose the Timer
```cs
MyTimer.Dispose();
```
# Manual Setup
You can manually configure the `Timer` and then `Start` it yourself instead of using `SetInterval`
## SetAction
Sets the `Action` that will be triggered by the TimerCallback when the `Period` has elapsed
```cs
MyTimer.SetAction(Action);
```
## SetInterval
Sets the Interval between `Actions` in `Milliseconds`.
```cs
MyTimer.SetInterval(int);
```
```cs
MyTimer.GetInterval();
```
## SetResolution
Set the `Resolution` of the Timer
```cs
MyTimer.SetResolution(int);
```
```cs
MyTimer.GetResolution();
```
The resolution is in milliseconds.
The `Resolution` increases with smaller values.
A resolution of 0 indicates periodic events should occur with the greatest possible accuracy.
To reduce system overhead, however, you should use the maximum value appropriate for your application.
The normal Resolution of a .Net Timer is around 12-15ms
## SetEventArgs
Set `EventArgs` of the Timer
```cs
MyTimer.SetEventArgs(EventArgs);
```
```cs
MyTimer.GetEventArgs();
```
## SetPeriodic
Set the Periodic/OneShot Mode of the <see cref="PrecisionTimer"/>
```cs
MyTimer.SetPeriodic(bool);
```
```cs
MyTimer.GetPeriodic();
```
`True` if the `PrecisionTimer` should raise the `Ticks` Event each time the interval elapses. (Periodic)
`False` if the `PrecisionTimer` should raise the event only once AFTER the first time the interval elapses. (One-Shot)
# Timing Settings
Global Multimedia Timer settings that affect your application
[Set the Applications Minimum Resolution](https://docs.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timebeginperiod)
```cs
TimingSettings.SetMinimumTimerResolution(0);
```
[Clear the Applications Minimum Resolution](https://docs.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timeendperiod)
```cs
TimingSettings.ClearMinimumTimerResolution(0);
```
## Multimedia Timer
Precision Timer.NET is a Multimedia Timer.
You can read more about Multimedia Timers on [MSDN](https://docs.microsoft.com/en-us/windows/win32/multimedia/multimedia-timer-reference)
# Tips
If you found this useful pleases consider leaving a tip
- [x] BTC: 1NXUg88UvRWYn1WTnikVNn2fbbEtuTeXzm
- [x] ETH: 0x50740d132481be4721b1742670031baee3655ec2
- [x] DOGE: DS6orKQwdK4sBTmwoS9NVqvWCKA5ksGPfa
- [x] LTC: Lbd3oMKeokyXUQaxBDJpMMNVUws5wYhQES
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
c#高精度毫秒定时器,实现windows高精度定时器功能,参考 C#上位机1ms级高精度定时任务讲解 https://www.bilibili.com/video/BV1fd4y1v7dK/?spm_id_from=333.337.search-card.all.click&vd_source=e821a225c7ba4a7b85e5aa6d013ac92e 高精度定时器的使用以及实现 https://blog.csdn.net/i78i845/article/details/130220156
资源推荐
资源详情
资源评论
收起资源包目录
高精度毫秒定时器 anlog 2024年5月10日.zip (41个子文件)
毫秒定时器
WindowsFormsApp1
WindowsFormsApp1
Form1.Designer.cs 3KB
packages.config 145B
App.config 187B
Form1.cs 2KB
obj
Debug
WindowsFormsApp1.csproj.AssemblyReference.cache 7KB
WindowsFormsApp1.csproj.FileListAbsolute.txt 1KB
WindowsFormsApp1.csproj.CoreCompileInputs.cache 42B
WindowsFormsApp1.exe 9KB
WindowsFormsApp1.pdb 32KB
DesignTimeResolveAssemblyReferencesInput.cache 2KB
WindowsFormsApp1.Form1.resources 180B
TempPE
.NETFramework,Version=v4.8.AssemblyAttributes.cs 210B
WindowsFormsApp1.csproj.SuggestedBindingRedirects.cache 0B
WindowsFormsApp1.csproj.GenerateResource.cache 126B
WindowsFormsApp1.csproj.CopyComplete 0B
WindowsFormsApp1.Properties.Resources.resources 180B
DesignTimeResolveAssemblyReferences.cache 137B
bin
Debug
WindowsFormsApp1.exe.config 187B
WindowsFormsApp1.exe 9KB
WindowsFormsApp1.pdb 32KB
PrecisionTimer.NET.xml 11KB
PrecisionTimer.NET.dll 18KB
Properties
Resources.Designer.cs 3KB
Settings.Designer.cs 1KB
Settings.settings 249B
AssemblyInfo.cs 1KB
Resources.resx 5KB
Program.cs 537B
WindowsFormsApp1.csproj 4KB
Form1.resx 6KB
WindowsFormsApp1.sln 1KB
.vs
WindowsFormsApp1
v17
DocumentLayout.json 4KB
.suo 67KB
FileContentIndex
d93497a1-2da1-45a7-a56f-0ff9b3d3e3b8.vsidx 37KB
packages
PrecisionTimer.NET.2.2.4
lib
netstandard2.0
PrecisionTimer.NET.xml 11KB
PrecisionTimer.NET.dll 18KB
PrecisionTimer.NET.2.2.4.nupkg 26KB
README.md 3KB
.signature.p7s 9KB
precisiontimer.net.2.4.0.3.nupkg 23KB
毫秒定时器学习笔记2022年12月29日.pptx 253KB
共 41 条
- 1
资源评论
anlog
- 粉丝: 1144
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功