■ Parallel 클래스 : ForEach 정적 메소드 사용하기

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


TestProject.zip


Program.cs

 

 

using System;

using System.Threading.Tasks;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

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

        ////////////////////////////////////////////////////////////////////////////////////////// Static

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

 

        #region 프로그램 시작하기 - Main()

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        private static void Main()

        {

            Console.WriteLine("BEGIN MAIN FUNCTION");

 

            Console.Title = "Parallel 클래스 : ForEach 정적 메소드 사용하기";

 

            Console.WriteLine("BEGIN GET ARRAY");

 

            string[] sourceArray = GetStringArray(100);

 

            Console.WriteLine("END GET ARRAY");

 

            Console.WriteLine("BEGIN PARALLEL FOREACH");

 

            ParallelOptions options = new ParallelOptions();

 

            options.MaxDegreeOfParallelism = sourceArray.Length;

 

            Parallel.ForEach(sourceArray, (item) => { Console.WriteLine(item); });

 

            Console.WriteLine("END PARALLEL FOREACH");

 

            Console.WriteLine("END MAIN FUNCTION");

        }

 

        #endregion

 

        #region 문자열 배열 구하기 - GetStringArray(count)

 

        /// <summary>

        /// 문자열 배열 구하기

        /// </summary>

        /// <param name="count">카운트</param>

        /// <returns>문자열 배열</returns>

        private static string[] GetStringArray(int count)

        {

            int countLength = count.ToString().Length;

 

            string[] array = new string[count];

 

            for(int i = 0; i < count; i++)

            {

                array[i] = "항목" + (i + 1).ToString("d" + countLength);

            }

 

            return array;

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker