티스토리 뷰
static field는 모든 Thread에서 공동으로 사용된다.
아래 예제를 살펴보자.
using System;
using System.Threading;
namespace ThreadTest
{
class Program
{
// Static fields are shared between all threads
static int count;
static void Main(string[] args)
{
new Thread(Go).Start();
Go();
}
static void Go()
{
for (int i = 0; i < 5; i++)
{
count++;
Console.WriteLine(count);
}
}
}
}
위의 예제에서 count는 static field이다.
두개의 thread가 count를 사용하는데, 공통으로 사용하게 된다.
실행 결과 화면은 아래와 같다.
2개의 thread가 공통의 instance를 사용한 앞의 예제와 동일한 결과를 얻었다.
아래 예제를 살펴보자.
using System;
using System.Threading;
namespace ThreadTest
{
class Program
{
// Static fields are shared between all threads
static int count;
static void Main(string[] args)
{
new Thread(Go).Start();
Go();
}
static void Go()
{
for (int i = 0; i < 5; i++)
{
count++;
Console.WriteLine(count);
}
}
}
}
위의 예제에서 count는 static field이다.
두개의 thread가 count를 사용하는데, 공통으로 사용하게 된다.
실행 결과 화면은 아래와 같다.
2개의 thread가 공통의 instance를 사용한 앞의 예제와 동일한 결과를 얻었다.
'Code > C#' 카테고리의 다른 글
Thread.Sleep() & TimeSpan.FromSeconds() (0) | 2007.12.09 |
---|---|
Thread 에서 locker의 사용 (0) | 2007.12.09 |
Thread에서 공동의 인스턴스 사용 예제 (0) | 2007.12.09 |
Thread 간단하게 시작하기 예제 (0) | 2007.12.09 |
Thread Join 사용법과 예제 (0) | 2007.12.08 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 애드센스감추기
- c#
- ScreenHunter
- registry
- AxWebBrowser
- .net framework
- autohotkey
- Automation
- Microsoft
- AdSense감추기
- 애드센스숨기기
- 스크린캡쳐
- WinAutomation
- Rollback Rx
- jre
- 유틸리티
- Phalanger
- Service pack
- download.com
- Regular Expressions
- tagREADYSTATE
- iText
- iTextSharp
- DotNetMagic
- windows
- java
- Sample Code
- AdSense숨기기
- READYSTATE_COMPLETE
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함