C# 2.0 에서는 ThreadStart delegate를 사용하지 않아도 된다. 아래 예제를 보자. 아래 예제는 앞 예제와 같은 것이다. 하지만 ThreadStart delegate를 사용하지 않았다. using System; using System.Threading; namespace ThreadSample { class Program { public const int Repetitions = 1000; static void Main(string[] args) { Thread myThread = new Thread(DoWork); myThread.Start(); for (int count = 0; count < Repetitions; count++) { Console.Write('-'); } myTh..
Thread 간에 서로 얼마자 자주 interupt 가 일어나는지를 알 수 있는 샘플 코드이다. 두개의 thread가 화면에 점과 대쉬를 표시한다. 결과 화면을 보면 인터럽트의 정도를 확인할 수 있다. using System; using System.Threading; namespace ThreadSample { class Program { public const int Repetitions = 1000; static void Main(string[] args) { ThreadStart myThreadStart = new ThreadStart(DoWork); Thread myThread = new Thread(myThreadStart); myThread.Start(); for (int count = 0;..
이 예제는 앞의 예제를 약간 변형한 것이다. Thread와 FileStream을 동시에 사용해보았다. FileStream 에서 FileMode.Append, FileAccess.Write, FileShare.Write 를 사용해서 복수개의 Thread가 File에 접근할 수 있도록했다. FileShare.Write 옵션을 사용하지 않으면, Exception이 발생한다. 이 부분을 이해하는 것이 중요하다. 아래는 코드이다. using System; using System.Threading; using System.IO; using System.Text; public class NameUsingThread { private int time; private Thread thread; public NameUsi..
Thread에 관한 3번째 샘플 코드이다. 이 샘플 코드는 Thread를 3개 실행 시키는 것이다. using System; using System.Threading; public class NameUsingThread { private int time; private Thread thread; public NameUsingThread(String n, int t) { time = t; thread = new Thread(new ThreadStart(Run)); thread.Name = n; thread.Start(); } public void Run() { for (int i = 1; i
이것은 앞의 예제를 약간 변형한 것이다. 2개의 Thread가 하나의 공통된 변수를 다루고 있다. 2개의 Thread가 하나의 int 변수에 발생한 난수를 더하고 있다. using System; using System.Threading; namespace SampleThread { class Program { static void Main(string[] args) { myRandom = new Random(); s = 0; Thread t1 = new Thread(new ThreadStart(method1)); t1.Start(); Thread t2 = new Thread(new ThreadStart(method2)); t2.Start(); } private static void method1() { ..
아래는 간단한 Thread 샘플 코드이다. 난수를 발생시키는 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.Star..
아래는 Extension Methods 예제이다. LINE A는 Extension Methods를 사용했고, LINE B는 Static Method를 사용했다. 둘의 선언 방법과 사용 방법을 비교해보자. Extension methods are static methods. Extension methods can only be declared in static classes. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string s = "9"; int ..
.NET Framework 3.5 발표와 함께 C# 3.0에 새로 추가된 것 중에 Extension Methods란 것이 있다. Extension Methods는 기존에 존재하는 Type에 Method를 추가할 수 있게 해주는 것이다. Extension Methods가 나오기 전에는, 이미 존재하는 Class에 새로운 Method를 추가하려면 상속 클래스를 만들어야했다. 하지만 Extension Methods를 사용하면 상속 클래스를 만들지 않고도 Method를 추가할 수 있는 것이다. 아래 예를 보자.
난수를 발생할 때, 중복되지 않는 것들로만 해야할 때가 있다. 이와 같은 경우에 사용할 수 있는 예제를 하나 만들어 보았다. List Generic Collection을 사용해서 만들었다. using System; using System.Collections.Generic; namespace RandomNumber { class Program { static void Main(string[] args) { Random myRandom = new Random(); List myList = new List(); int r; for (int i = 0; i < 3; i++) { do { r = myRandom.Next(5); } while (myList.Contains(r)); myList.Add(r); } ..
Jagged Array는 Multidimensional Array와는 다르므로 주의를 요합니다. 아래는 Jagged Array 선언 방법을 보여주는 샘플 코드입니다. Multidimensional Array와 헷갈리지 않도록 앞에 있는 Multidimensional Array 선언 방법과 비교해가며 보시기 바랍니다. namespace ArraySample { class Program { static void Main(string[] args) { // Jagged Array int[][] zArray; zArray = new int[3][]; zArray[0] = new int[] { 1, 2, 3 }; zArray[1] = new int[] { 1, 2 }; zArray[2] = new int[] { ..
- Total
- Today
- Yesterday
- c#
- 애드센스숨기기
- Sample Code
- ScreenHunter
- iText
- READYSTATE_COMPLETE
- DotNetMagic
- 스크린캡쳐
- 유틸리티
- iTextSharp
- AdSense감추기
- windows
- Automation
- Regular Expressions
- 애드센스감추기
- AdSense숨기기
- Service pack
- jre
- java
- Phalanger
- AxWebBrowser
- WinAutomation
- tagREADYSTATE
- registry
- Rollback Rx
- Microsoft
- download.com
- .net framework
- autohotkey
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |