DataGridView 사용에 대한 간단한 예제이다. DataGridView.ColumnCount 를 사용해서 열의 갯수를 정한다. DataGridView.Columns[].Name 으로 각 열의 이름을 정한다. DataGridView.Rows.Add() 를 이용해서 행을 추가한다. using System; using System.Windows.Forms; namespace DataGridViewSample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.dataGridView1.ColumnCount ..
두 시간 사이의 간격을 계산하기 위해서 DateTime 과 TimeSpan 을 사용할 수 있다. DateTime 은 측정하려는 두 시간을 구할 때 사용한다. TimeSpan 은 두 시간 사이의 간격을 계산할 때 사용한다. 아래 예제를 보자. using System; using System.Threading; namespace ThreadTest { class Program { static void Main(string[] args) { int result; int signature; TimeSpan oneSecond = TimeSpan.FromSeconds(1); Console.WriteLine(oneSecond); for (int i = 0; i < 10; i++) { DateTime old = Dat..
Thread.Sleep() 을 사용하면 일정 시간 동안 Thread를 멈출 수 있다. TimeSpan.FromSeconds() 을 사용하면 편하게 milli second 계산을 할 수 있다. 아래 예제를 살펴보자. using System; using System.Threading; namespace ThreadTest { class Program { static object locker = new object(); static void Main(string[] args) { new Thread(Go).Start(); for (int i = 0; i < 20; i++) { Console.Write("."); Thread.Sleep(TimeSpan.FromSeconds(1)); } } static void ..
thread의 실행을 컨트롤하기 위해서 locker를 사용할 수 있다. locker는 오로지 lock을 하는 용도로만 쓰인다. 아래 예제를 살펴보자. using System; using System.Threading; namespace ThreadTest { class Program { static object locker = new object(); static void Main(string[] args) { new Thread(Go).Start(); lock (locker) { for (int i = 0; i < 500; i++) { Console.Write("."); } } } static void Go() { lock (locker) { for (int i = 0; i < 500; i++) { C..
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가 coun..
아래는 두개의 Thread가 공동의 instance를 사용한 예제이다. Foo 클래스 인스턴스인 foo를 공동으로 사용한 두개의 thread가 실행되었다. using System; using System.Threading; namespace ThreadTest { class Program { static void Main(string[] args) { Foo foo = new Foo(); new Thread(foo.Go).Start(); foo.Go(); } } class Foo { private int count = 0; public void Go() { for (int i = 0; i < 5; i++) { count++; Console.WriteLine(count); } } } } 실행 결과 화면은 ..
아래 예제는 Thread를 간단하게 시작하는 방법을 사용한 것이다. 단 한줄로 Thread를 시작한다. using System; using System.Threading; namespace ThreadTest { class Program { static void Main(string[] args) { new Thread(Go).Start(); // Call Go() on a new thread Go(); // Call Go() on the main thread } static void Go() { for (int i = 0; i < 5; i++) Console.WriteLine(i); } } } 아래는 실행 결과 화면이다.
하나의 Thread가 실행되는 도중, 다른 Thread가 완료되기를 기다려야할 때가 있다. 이때 사용할 수 있는 것이 Join method이다. Join method는 지정된 Thread가 끝날 때까지 기다리라는 명령어이다. 아래의 예제를 보자. using System; using System.Threading; namespace JoinTest { class Program { static void Main(string[] args) { Thread worker = new Thread(new ThreadStart(DoWork)); worker.Start(); worker.Join(); Console.WriteLine("Done"); } static void DoWork() { for (int i = 0;..
Thread를 중지시키기 위해서 Abort method를 사용할 수 있다. Abort method 로 thread 를 중지시키면 ThreadAbortException 이 발생한다. 아래 예제는 ThreadAbortException 을 발생시키는 예제이다. thread 가 실행되는 도중 enter 키를 누르면, thread 가 정지되고, ThreadAbortException 이 발생한다. using System; using System.Threading; namespace AbortThreads { class Program { static void Main(string[] args) { Thread.CurrentThread.Name = "MAIN"; PrintMessage("Application Start..
앞 예제에서는 Monitor 클래스를 사용해서 object를 lock 시켰다. 이번에는 lock keyword를 사용해보자. lock keyword를 사용하면 Monitor를 사용하는 것보다 안전하고 간편하게 thread를 사용할 수 있다. 아래 예제를 보자. 예제에서 보면 Monitor.Enter 와 Monitor.Exit 대신 lock 블럭으로 감싸준 것을 알 수 있다. using System; using System.Collections.Generic; using System.Threading; namespace ThreadSample { class Program { private static Queue myQueue = new Queue(); static void Main(string[] args..
- Total
- Today
- Yesterday
- DotNetMagic
- Service pack
- Microsoft
- Rollback Rx
- iText
- windows
- 애드센스감추기
- Regular Expressions
- Automation
- READYSTATE_COMPLETE
- registry
- jre
- 애드센스숨기기
- AxWebBrowser
- 유틸리티
- WinAutomation
- Phalanger
- AdSense감추기
- tagREADYSTATE
- 스크린캡쳐
- autohotkey
- java
- download.com
- Sample Code
- ScreenHunter
- AdSense숨기기
- .net framework
- c#
- iTextSharp
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |