티스토리 뷰
아래는 간단한 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
- ScreenHunter
- iText
- Sample Code
- autohotkey
- 유틸리티
- iTextSharp
- java
- AdSense숨기기
- Automation
- 애드센스숨기기
- READYSTATE_COMPLETE
- Microsoft
- 애드센스감추기
- Phalanger
- c#
- DotNetMagic
- AxWebBrowser
- AdSense감추기
- WinAutomation
- download.com
- .net framework
- registry
- 스크린캡쳐
- tagREADYSTATE
- Service pack
- windows
- jre
- Rollback Rx
- Regular Expressions
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함