Windows Form Application의 path를 구하는 방법은 간단하다. Application.ExecutablePath 를 사용하면 된다. 아래는 사용 예제이다. using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.textBox1.Text = Application.ExecutablePath; } } }
아래는 실행중인 어플리케이션의 현재 위치를 구하는 간단한 예제이다. 이 예제는 System.Reflection 을 사용했다. Assembly.GetExecutingAssembly() 은 현재의 Assembly를 반환한다. Location Property는 Assembly의 위치를 반환한다. using System; using System.Reflection; namespace Test { class Program { static void Main(string[] args) { string myPath = Assembly.GetExecutingAssembly().Location; Console.WriteLine(myPath); Console.Read(); } } }
BinaryFormatter.Serialize 와 BinaryFormatter.Deserialize 를 사용한 예제입니다. 아래 예제를 보면 [Serializable] Attribute를 사용한 Name 클래스만 Serialize & Deserialize 한 것을 알 수 있습니다. 이 예제는 사실 BinaryFormatter.Serialize & BinaryFormatter.Deserialize 의 버그 여부를 조사하기 위해서 만들었습니다. Serialize 후 일부 데이터를 변경하고, 다시 Deserialize 했을 때, 혹시 버그가 있나 검사해봤는데, 정상이었습니다. BinaryFormatter.Serialize & BinaryFormatter.Deserialize 는 generic static me..
Generic Method 를 사용하면 상당히 유용한 Serialization 을 구사할 수 있다. 아래 예제는 Generic Method 를 사용하여 어떠한 Type이라도 쉽게 Serialize & Deserialize 할 수 있도록 한 것이다. 이런 것들은 실전에서 유용하게 이용될 수 있다. using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace GenericSerializer { public static class Serializer { public static void Export(string otherFile, T otherT) { using (Stream s = File.Open(..
객체를 serialize 하여 파일에 저장하는 방법은 아래와 같다. serialize 하려는 클래스에 [Serializable] Attribute 를 붙인다. Stream 으로 serialize 파일을 연다. BinaryFormatter.Serialize 로 serialize 된 객체를 파일에 저장한다. BinaryFormatter.Deserialize 를 사용하면 serialize 되어 파일에 저장된 객체를 불러올 수 있다. 아래 예제를 살펴보자. using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace SerializableAttribute0001 { class Program { stati..
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..
- Total
- Today
- Yesterday
- iText
- Sample Code
- Automation
- 스크린캡쳐
- .net framework
- READYSTATE_COMPLETE
- download.com
- DotNetMagic
- ScreenHunter
- c#
- AxWebBrowser
- Rollback Rx
- Microsoft
- registry
- 유틸리티
- jre
- WinAutomation
- 애드센스숨기기
- Regular Expressions
- java
- iTextSharp
- autohotkey
- Service pack
- windows
- AdSense감추기
- 애드센스감추기
- Phalanger
- AdSense숨기기
- tagREADYSTATE
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |