예외 발생: 'System.TypeInitializationException'(System.Management.dll) 처리되지 않은 'System.TypeInitializationException' 형식의 예외가 System.Management.dll에서 발생했습니다. The type initializer for 'System.Management.ManagementPath' threw an exception. 'ConsoleApp2.exe'(CoreCLR: clrhost): 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.NetCoreApp.dll'을(를) 로드했습니다. 기호를 로드하지 않고 건너뛰었습니다. 모듈이 최적화되어 있고 '내 코드만' 디버거 옵션을 사용하도록 설정되어 있습니다. 'ConsoleApp2.exe'(CoreCLR: clrhost): 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.9\netstandard.dll'을(를) 로드했습니다. 기호를 로드하지 않고 건너뛰었습니다. 모듈이 최적화되어 있고 '내 코드만' 디버거 옵션을 사용하도록 설정되어 있습니다. '[16900] ConsoleApp2.exe' 프로그램이 종료되었습니다(코드: 3221225786 (0xc000013a)).
코드는 요렇게 짯어요
using System;
using System.Management;
using System.Threading;
namespace CheckCPUCores
{
class Program
{
static void Main(string[] args)
{
int requiredCores = 6;
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject obj in collection)
{
int coreCount = Convert.ToInt32(obj["NumberOfCores"]);
Console.WriteLine("CPU Cores: " + coreCount);
if (coreCount < requiredCores)
{
Console.WriteLine("CPU 코어 개수가 " + requiredCores + "개 미만입니다. 프로그램을 종료합니다.");
Thread.Sleep(1000);
return;
}
}
Console.WriteLine("CPU 코어 개수가 충분합니다. 프로그램을 실행합니다.");
Console.WriteLine("sss");
}
}
}