修改长时间内存会炸

This commit is contained in:
2026-03-25 17:51:43 +08:00
parent 1840794f40
commit d0c626c189
61 changed files with 82737 additions and 271 deletions

View File

@@ -3,6 +3,9 @@ using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using Common;
using System.Timers;
using CommonEntity;
namespace ConsoleApplication4
{
@@ -21,39 +24,85 @@ namespace ConsoleApplication4
{
private static bool _isRunning = true;
static void Main(string[] args)
public static System.Timers.Timer CPUTimer = null;
public static void StartCPUTongJiTask()
{
Console.CancelKeyPress += (sender, e) =>
{
_isRunning = false;
e.Cancel = true;
};
try
{
var udpClient = new UdpClient(3340);
udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024;
// 开始接收
udpClient.BeginReceive(ReceiveCallback, new UdpState(udpClient));
Console.WriteLine("UDP服务器已启动按Ctrl+C停止...");
// 保持程序运行
while (_isRunning)
{
Thread.Sleep(100);
}
udpClient.Close();
Console.WriteLine("服务器已停止");
CPUTimer = new System.Timers.Timer();
CPUTimer.Elapsed += new ElapsedEventHandler(CPUtimer_Elapsed);
//10分钟统计一次
//现在修改成20秒
//CPUTimer.Interval = 1 * 60 * 1000;
CPUTimer.Interval = 1000;
CPUTimer.Start();
}
catch (Exception ex)
{
Console.WriteLine($"启动失败: {ex.Message}");
}
}
static private void CPUtimer_Elapsed(object sender, ElapsedEventArgs e)
{
var T = sender as System.Timers.Timer;
try
{
// 防止重入
T.Stop();
double d = CPUData.GetCPU();
DataTongJi.CPU_Data.Add(d);
Console.WriteLine("aaaaaaaaaa");
}
catch (Exception ex)
{
Console.WriteLine("出错了:"+ex.Message);
}
finally
{
// 恢复计时器
T.Start();
}
}
static void Main(string[] args)
{
StartCPUTongJiTask();
var a= CPUData.GetCPU();
Console.WriteLine(a);
var b = CPUData.GetNowPrecise();
Console.WriteLine(b.ToString());
Console.ReadLine();
//Console.CancelKeyPress += (sender, e) =>
//{
// _isRunning = false;
// e.Cancel = true;
//};
//try
//{
// var udpClient = new UdpClient(3340);
// udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024;
// // 开始接收
// udpClient.BeginReceive(ReceiveCallback, new UdpState(udpClient));
// Console.WriteLine("UDP服务器已启动按Ctrl+C停止...");
// // 保持程序运行
// while (_isRunning)
// {
// Thread.Sleep(100);
// }
// udpClient.Close();
// Console.WriteLine("服务器已停止");
//}
//catch (Exception ex)
//{
// Console.WriteLine($"启动失败: {ex.Message}");
//}
}
public static void ReceiveCallback(IAsyncResult ar)
{
UdpState state = ar.AsyncState as UdpState;