관리 메뉴

안까먹을라고 쓰는 블로그

[C#] delegate / Event / Thread 본문

Language/C#

[C#] delegate / Event / Thread

YawnsDuzin 2012. 12. 26. 17:21

 

반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
 
namespace Event_Test
{
    // 일종의 CallBack함수의 함수포인터로 이벤트 발생시 호출 할 Method의 타입에 맞추어 선언
    delegate void EventDelegate();                              // Delegate 선언
    class clsEvent
    {
        public event EventDelegate _EventDelegate;              // Event 선언
 
        // 실제 호출될 Method로 delegate형식에 맞추어 구현
        public void btnClick()
        {
            _EventDelegate();
        }
    }
 
    class Program
    {
        // delegate Function
        private void Delegate_Fun()
        {
            EventDelegate df = new EventDelegate(Click);        // delegate Initial
            df += new EventDelegate(Click);                     // delegate ++
            df -= new EventDelegate(Click);                     // delegate --
            df();                                               // delegate Excute
        }
 
        // Thread(delegate Function)
        private void Thread_Fun()
        {
            Thread th;
            ThreadStart ths = new ThreadStart(Click);           // ThreadStart = delegate
            th = new Thread(ths);
            th.Start();
        }
 
        // delegate + Event Function
        static void Main(string[] args)
        {
            clsEvent Ev = new clsEvent();
 
            // .Event += new delegate(함수);
            Ev._EventDelegate += new EventDelegate(Click);      // Method를 Event에 등록
 
            Ev.btnClick();
        }
 
        private static void Click()
        {
            Console.WriteLine("Click Event!");
        }
    }
}
cs


반응형

'Language > C#' 카테고리의 다른 글

[C#] Service Project 만들기  (0) 2013.05.10
[C#] 비동기 통신관련 공부할것  (0) 2013.04.29
[C#] 프로그램 중복실행 방지  (0) 2012.12.11
[C#] INI 읽고/쓰기  (0) 2012.12.10
[C#] 부모폼과 자식폼의 참조  (0) 2012.10.30
Comments