一秒钟控制25个计算量的方法
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { static int totalCount = 0; static int count = 0; static DateTime checkTime = DateTime.Now; static void Main(string[] args) { while (true) { if (count == 0) { checkTime = DateTime.Now; } totalCount++; count++; Console.WriteLine(string.Format("{0} count:{1}", DateTime.Now, count.ToString())); if (count == 25) { TimeSpan ts = DateTime.Now - checkTime; if (ts.TotalMilliseconds < 1000) { count = 0; System.Threading.Thread.Sleep(1000 - (int)ts.TotalMilliseconds); } else { count = 0; } } if (totalCount == 100) break; } Console.ReadLine(); } }}