Caharp 多核加速
public class BatchImageExtractor { public static async Task ExtractImagesParallel( List<string> pdfPaths, string outputFolder) { // 使用并行处理(注意控制并发度) var options = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount - 1 }; await Parallel.ForEachAsync(pdfPaths, options, async (pdfPath, ct) => { try { var fileName = Path.GetFileNameWithoutExtension(pdfPath); var pdfOutputFolder = Path.Combine(outputFolder, fileName); await Task.Run(() => ImageExtractor.ExtractImages(pdfPath, pdfOutputFolder), ct); } catch (Exception ex) { Console.WriteLine($"处理失败 {pdfPath}: {ex. Message}"); } }); } }
转自:

浙公网安备 33010602011771号