첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System.Threading;

ThreadSample threadSample = new ThreadSample(10);

Thread thread = new Thread(new ThreadStart(threadSample.DisplayCount));

thread.Name = "thread";

thread.Start();

 

728x90

 

▶ ThreadSample.cs

using System;
using System.Threading;

/// <summary>
/// 스레드 샘플
/// </summary>
public class ThreadSample
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region Field

    /// <summary>
    /// 루프 카운트
    /// </summary>
    private readonly int loopCount;

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - ThreadSample(loopCount)

    /// <summary>
    /// 생성자
    /// </summary>
    /// <param name="loopCount">루프 카운트</param>
    public ThreadSample(int loopCount)
    {
        this.loopCount = loopCount;
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 카운트 표시하기 - DisplayCount()

    /// <summary>
    /// 카운트 표시하기
    /// </summary>
    public void DisplayCount()
    {
        for(int i = 1; i <= loopCount; i++)
        {
            Thread.Sleep(TimeSpan.FromSeconds(0.5));

            Console.WriteLine("{0} : 카운트 {1}", Thread.CurrentThread.Name, i);
        }
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요