첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ 프로세서 수 구하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

using System.Management;

using System.Windows.Forms;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : Form

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            #region 이벤트를 설정한다.

 

            this.Load += Form_Load;

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

 

        /// <summary>

        /// 폼 로드시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Form_Load(object sender, EventArgs e)

        {

            int physicalProcessorCount;

            int coreCount;

            int logicalProcessorCount;

 

            SetProcessorCount(out physicalProcessorCount, out coreCount, out logicalProcessorCount);

 

            this.physicalProcessorCountTextBox.Text = physicalProcessorCount.ToString();

            this.coreCountTextBox.Text              = coreCount.ToString();

            this.logicalProcessorCountTextBox.Text  = logicalProcessorCount.ToString();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////// Function

 

        #region 프로세서 카운트 설정하기 - SetProcessorCount(physicalProcessorCount, coreCount, logicalProcessorCount)

 

        /// <summary>

        /// 프로세서 카운트 설정하기

        /// </summary>

        /// <param name="physicalProcessorCount">물리적 프로세서 카운트</param>

        /// <param name="coreCount">코어 카운트</param>

        /// <param name="logicalProcessorCount">논리적 프로세서 카운트</param>

        private void SetProcessorCount(out int physicalProcessorCount, out int coreCount, out int logicalProcessorCount)

        {

            string                   query;

            ManagementObjectSearcher managementObjectSearcher;

 

            physicalProcessorCount = 0;

 

            query = "SELECT * FROM Win32_ComputerSystem";

 

            managementObjectSearcher = new ManagementObjectSearcher(query);

 

            foreach(ManagementObject managementObject in managementObjectSearcher.Get())

            {

                physicalProcessorCount = int.Parse(managementObject["NumberOfProcessors"].ToString());

            }

 

            coreCount = 0;

 

            query = "SELECT * FROM Win32_Processor";

 

            managementObjectSearcher = new ManagementObjectSearcher(query);

 

            foreach(ManagementObject proc in managementObjectSearcher.Get())

            {

                coreCount += int.Parse(proc["NumberOfCores"].ToString());

            }

 

            logicalProcessorCount = Environment.ProcessorCount;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요