본문 바로가기
300x250

C#/책 예제16

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.
300x250