线程池_ThreadPool
2020-12-13 01:38
标签:rectangle hal ext object map empty 状态 user linq 线程池_ThreadPool 标签:rectangle hal ext object map empty 状态 user linq 原文地址:https://www.cnblogs.com/Jeely/p/11003519.htmlusing System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/*
* 简化多线程使用,发挥主机最大性能
*
* 网论,可以不修改最大线程数,框架会根据实时资源情况启动任务,带内存保守机制
* 经测试,8 核心时可以达到理想状态,使用 32 核心CPU时,仅发挥CPU(内存)不到50%能力
* 结论,自己取核心数-1,指定给线程池,内存不足时线程池有保护功能,目前来看不用管内存问题
* 异步读写,计算量 > 读写量时,异步数可以等于核心数,否则 。。。
*
*/
namespace 线程池_ThreadPool
{
class Program
{
static void Main(string[] args)
{
//设置最大任务数
int num = getNumber();
ThreadPool.SetMaxThreads(num, num);
string[] files = new string[10000];
// 1 匿名函数
for (int i = 0; i
{
//using (Bitmap map = new Bitmap(filePath))
//{
// BitmapData bmpData = map.LockBits(new Rectangle(Point.Empty, map.Size),
// ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
// byte[] buffer = new byte[bmpData.Stride * bmpData.Height];
// Marshal.Copy(bmpData.Scan0, buffer, 0, buffer.Length);
// // do something at this map...
// Marshal.Copy(buffer, 0, bmpData.Scan0, buffer.Length);
// map.UnlockBits(bmpData);
// map.Save(filePath);
// map.Dispose();
//}
//GC.Collect();
});
}
// 2 调外部函数
for (int i = 0; i
/// 获取核心数
///
///