728x90
Thread 관련 예제
using System; using System.Threading; namespace Study_CS_ConsoleApp { class Program { static Thread threadA = new Thread(FuncA); static Thread threadB = new Thread(FuncB); static Thread threadC = new Thread(FuncC); static void FuncA() { for(int i=0; i<50; i++) { if (i > 30) threadA.Abort(); Console.WriteLine("A : Count = " + i); } } static void FuncB() { for (int i=0; i<50; i++) { System.Threading.Thread.Sleep(100); Console.WriteLine("B : Count = " + i); } } static void FuncC() { for (int i = 0; i < 50; i++) { Console.WriteLine("C : Count = " + i); threadC.Suspend(); } } static void Main(string[] args) { threadA.Start(); threadB.Start(); threadC.Start(); } } }
suspend()와 resume()
using System; using System.Threading; namespace Study_CS_ConsoleApp { class Program { static Thread threadA = new Thread(FuncA); static Thread threadB = new Thread(FuncB); static void FuncA() { for(int i=0; i<=10; i++) { System.Threading.Thread.Sleep(100); Console.WriteLine("A : Count = " + i); if(i == 0) // 조건문이 없으면 또 다시 Suspend threadA.Suspend(); } } static void FuncB() { for (int i=0; i<=10; i++) { System.Threading.Thread.Sleep(100); Console.WriteLine("B : Count = " + i); } threadA.Resume(); } static void Main(string[] args) { threadA.Start(); threadB.Start(); } } }
delegate
using System; using System.Threading; namespace Study_CS_ConsoleApp { class Program { // 델리게이트 선언 public delegate int cal(int a, int b); public static int Plus(int a, int b) { return a + b; } public static int Minus(int a, int b) { return a - b; } static void Main(string[] args) { cal plus = new cal(Plus); cal minus = new cal(Minus); Console.WriteLine(plus(4, 6)); Console.WriteLine(minus(11, 5)); } } }
'Study > C#' 카테고리의 다른 글
c#트랙바를 통한 볼륨 조절 (0) | 2017.05.18 |
---|---|
IP 주소 정수로 변환 (0) | 2017.05.16 |
C# MS-SQL 연동 (0) | 2017.04.14 |
C# 네트워크 기본 (1) | 2017.04.12 |
C# 예외처리, delegate (0) | 2017.04.10 |