본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF C# - 단일 스레드 예제( Threading/ Thread )

728x90
반응형

WPF C# - 단일 스레드 예제( Threading/ Thread )




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
        bool gogogo = false;
        delegate void Work();
 
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            gogogo = !gogogo;   // ON/OFF 스위치 역할 ( False 이면 True 로, True 이면 False 로 바꿔준다 )
 
            if (gogogo)
            {
                button1.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Work(Display));
                button1.Content = "Stop";
            }
            else button1.Content = "Resume";
        }
 
        int k = 0;
        public void Display()
        {
            k++;
            lbl.Content = k;
            if (gogogo) button1.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Work(Display));
        }
 
cs


내용출처 : http://techlog.gurucat.net/167


728x90
반응형