Monitor.Enter 와 Monitor.Exit 샘플코드이다. Monitor.Enter 로 필요한 object를 lock 시킨다. Monitor.Enter 로 lock 시킨 object 는 Monitor.Exit로 풀어준다. 아래 코드에서 주의할 것이 하나 있는데, 바로 foreach 문이다. foreach 문이 완료되기 전에 대상 object 의 내용이 변해서는 안되다. 그래서 foreach 문은 그 앞뒤에 Monitor.Enter 와 Monitor.Exit 를 넣었다. using System; using System.Collections.Generic; using System.Threading; namespace ThreadSample { class Program { private static Q..
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 ..
난수를 발생할 때, 중복되지 않는 것들로만 해야할 때가 있다. 이와 같은 경우에 사용할 수 있는 예제를 하나 만들어 보았다. 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
- 애드센스숨기기
- windows
- WinAutomation
- download.com
- Phalanger
- AdSense감추기
- 스크린캡쳐
- Sample Code
- jre
- iTextSharp
- tagREADYSTATE
- 애드센스감추기
- autohotkey
- java
- registry
- DotNetMagic
- Rollback Rx
- READYSTATE_COMPLETE
- iText
- c#
- Automation
- 유틸리티
- ScreenHunter
- Service pack
- .net framework
- Regular Expressions
- Microsoft
- AxWebBrowser
- AdSense숨기기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |