본문 바로가기
300x250

전체 글473

C# Task async 한정자와 await 연산자 사용하기. using System; using System.Threading.Tasks; namespace ThreadNTask { class Program { static void Main(string[] args) { Caller(); Console.ReadLine(); } async static private void MyMethodAsync(int count) { Console.WriteLine("C"); Console.WriteLine("D"); await Task.Run(async() => { for(int i = 1; i < count; i++) { Console.WriteLine($"{i}/{count}."); await Task.Delay(1000); } }); Console.WriteLine("G.. 2019. 6. 8.
C# Task Parallel 클래스 사용하기. using System; using System.Collections.Generic; using System.Threading.Tasks; namespace ThreadNTask { class Program { static void Main(string[] args) { long from = Convert.ToInt64(args[0]); long to = Convert.ToInt64(args[1]); Console.WriteLine("Please press enter to start"); Console.ReadLine(); Console.WriteLine("Started"); DateTime startTime = DateTime.Now; List total = new List(); Parallel.For.. 2019. 6. 8.
C# Task Task<TResult> 클래스 사용하기. using System; using System.Collections.Generic; using System.Threading.Tasks; namespace ThreadNTask { class Program { static void Main(string[] args) { long from = Convert.ToInt64(args[0]); long to = Convert.ToInt64(args[1]); int taskCount = Convert.ToInt32(args[2]); Func FindPrintFunc = (objRange) => { long[] range = (long[])objRange; List found = new List(); for(long i = range[0]; i < range[1].. 2019. 6. 8.
C# Task Task 클래스 사용하기. using System; using System.IO; using System.Threading; using System.Threading.Tasks; namespace ThreadNTask { class Program { static void Main(string[] args) { string srcFile = args[0]; Action fileCopyAction = (object state) => { string[] paths = (string[])state; File.Copy(paths[0], paths[1]); Console.WriteLine("TaskID: {0}, ThreadID: {1}, {2} was copied to {3}", Task.CurrentId, Thread.CurrentThr.. 2019. 6. 8.
C# Thread Monitor.Wait 그리고 Monitor.Pulse 사용하기 using System; using System.Threading; namespace ThreadNTask { class Program { static void Main(string[] args) { Counter counter = new Counter(); Thread increaseThread = new Thread(new ThreadStart(counter.Increase)); Thread decreaseThread = new Thread(new ThreadStart(counter.Decrease)); increaseThread.Start(); decreaseThread.Start(); increaseThread.Join(); decreaseThread.Join(); Console.WriteLine.. 2019. 6. 8.
C# Thread Monitor 키워드를 이용한 동기화 using System; using System.Threading; namespace ThreadNTask { class Program { static void Main(string[] args) { Counter counter = new Counter(); Thread increaseThread = new Thread(new ThreadStart(counter.Increase)); Thread decreaseThread = new Thread(new ThreadStart(counter.Decrease)); increaseThread.Start(); decreaseThread.Start(); increaseThread.Join(); decreaseThread.Join(); Console.WriteLine.. 2019. 6. 8.
C# Thread lock 키워드를 이용한 동기화 using System; using System.Threading; namespace ThreadNTask { class Program { static void Main(string[] args) { Counter counter = new Counter(); Thread increaseThread = new Thread(new ThreadStart(counter.Increase)); Thread decreaseThread = new Thread(new ThreadStart(counter.Decrease)); increaseThread.Start(); decreaseThread.Start(); increaseThread.Join(); decreaseThread.Join(); Console.WriteLine.. 2019. 6. 8.
C# Thread 인터럽트로 종료하기. using System; using System.Threading; namespace ThreadNTask { class Program { static void Main(string[] args) { SlideTask slideTask = new SlideTask(100); Thread thread = new Thread(new ThreadStart(slideTask.KeepAlive)); thread.IsBackground = true; Console.WriteLine("스레드 시작"); thread.Start(); Thread.Sleep(100); Console.WriteLine("스레드 종료"); thread.Interrupt(); Console.WriteLine("스레드가 멈출때까지 대기"); t.. 2019. 6. 8.
300x250