網站首頁 編程語言 正文
最近程序上用到了計時功能,對某個模塊進行計時,暫停的時候模塊也需要暫停,啟動的時候計時繼續
用到了Stopwatch
Stopwatch的命名空間是using System.Diagnostics;
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp3 { class Program { static void Main(string[] args) { Stopwatch sw = new Stopwatch(); ////重新設置為零 //sw.Reset(); ////重新設置并開始計時 //sw.Restart(); ////結束計時 //sw.Stop(); //獲取運行時間間隔 TimeSpan ts = sw.Elapsed; //獲取運行時間[毫秒] long times = sw.ElapsedMilliseconds; //獲取運行的總時間 long times2 = sw.ElapsedTicks; //判斷計時是否正在進行[true為計時] bool isrun = sw.IsRunning; //獲取計時頻率 long frequency = Stopwatch.Frequency; //計時開始 sw.Start(); Thread.Sleep(1000); //計時結束 sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); Console.ReadLine(); Thread.Sleep(2000); Thread.Sleep(3000); } } }
需要進一步研究的同學可以查看官方文檔
Stopwatch 類 (System.Diagnostics) | Microsoft Docs
原文鏈接:https://www.cnblogs.com/xing2/p/15945256.html
相關推薦
- 2022-11-23 Python字典高級用法深入分析講解_python
- 2022-08-16 Python中的枚舉函數enumerate()的具體用法_python
- 2022-07-21 toggleRowSelection失效的2個原因
- 2022-12-14 Tensorflow2.1?完成權重或模型的保存和加載_python
- 2023-06-03 redis中刪除操作命令_Redis
- 2022-02-16 oracle導出表報錯Access violation at address
- 2022-04-15 python實現請求數據包簽名_python
- 2022-12-22 C++?Boost?Foreach超詳細分析講解_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支