티스토리 뷰
아래는 간단한 Thread 샘플 코드이다.
난수를 발생시키는 2개의 Thread가 있고, 발생한 난수만큼 Sleep 한다.
난수를 발생시키는 2개의 Thread가 있고, 발생한 난수만큼 Sleep 한다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace SampleThread
{
class Program
{
static void Main(string[] args)
{
myRandom = new Random();
Thread t1 = new Thread(new ThreadStart(method1));
t1.Start();
Thread t2 = new Thread(new ThreadStart(method2));
t2.Start();
}
private static void method1()
{
for (int i = 0; i < 5; i++)
{
r = myRandom.Next(6) * 1000;
Console.WriteLine("[{0,-10}]", r);
Thread.Sleep(r);
}
}
private static void method2()
{
for (int i = 0; i < 5; i++)
{
r = myRandom.Next(6) * 1000;
Console.WriteLine("[{0,10}]", r);
Thread.Sleep(r);
}
}
private static Random myRandom;
private static int r;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace SampleThread
{
class Program
{
static void Main(string[] args)
{
myRandom = new Random();
Thread t1 = new Thread(new ThreadStart(method1));
t1.Start();
Thread t2 = new Thread(new ThreadStart(method2));
t2.Start();
}
private static void method1()
{
for (int i = 0; i < 5; i++)
{
r = myRandom.Next(6) * 1000;
Console.WriteLine("[{0,-10}]", r);
Thread.Sleep(r);
}
}
private static void method2()
{
for (int i = 0; i < 5; i++)
{
r = myRandom.Next(6) * 1000;
Console.WriteLine("[{0,10}]", r);
Thread.Sleep(r);
}
}
private static Random myRandom;
private static int r;
}
}
'Code > C#' 카테고리의 다른 글
| [C#] Thread 샘플 코드 3 (0) | 2007.12.07 |
|---|---|
| [C#] Thread 샘플 코드 2 (0) | 2007.12.07 |
| [C#] Extension Methods 샘플 코드 (0) | 2007.12.02 |
| [C#] 중복되지 않는 난수 발생 샘플 코드 (0) | 2007.11.29 |
| [C#] Jagged Array 선언 방법 (0) | 2007.11.29 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Sample Code
- Phalanger
- AxWebBrowser
- 애드센스감추기
- 애드센스숨기기
- Microsoft
- iTextSharp
- 유틸리티
- tagREADYSTATE
- windows
- READYSTATE_COMPLETE
- .net framework
- c#
- autohotkey
- jre
- java
- ScreenHunter
- 스크린캡쳐
- AdSense숨기기
- download.com
- Regular Expressions
- Service pack
- Rollback Rx
- registry
- DotNetMagic
- WinAutomation
- Automation
- AdSense감추기
- iText
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함