using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static PDFMonitor_SVG.Entities; namespace PDFMonitor_SVG { internal class Entities { public const int DEFAULT_DPI = 96; public const double DEFAULT_RATIO = 25.4; public static int px2mm(double px) { return (int)Math.Round(px / DEFAULT_DPI * DEFAULT_RATIO); } //仿FixedThreadPool public class FixedThreadPool { private readonly BlockingCollection _taskQueue; private readonly Thread[] _threads; public FixedThreadPool(int size) { _taskQueue = new BlockingCollection(); _threads = new Thread[size]; for (int i = 0; i < size; i++) { _threads[i] = new Thread(Worker); _threads[i].Start(); } } public void Execute(Action action) { _taskQueue.Add(action); } private void Worker() { foreach (var task in _taskQueue.GetConsumingEnumerable()) { task(); } } public void Shutdown() { _taskQueue.CompleteAdding(); foreach (var thread in _threads) { thread.Join(); } } } public class SVGTaskInfo { private string width; private string height; private string svgPath; private string svgFileName; public SVGTaskInfo() { } public string SvgPath { get => svgPath; set => svgPath = value; } public string Height { get => height; set => height = value; } public string Width { get => width; set => width = value; } public string SvgFileName { get => svgFileName; set => svgFileName = value; } } } }