본문 바로가기
300x250

C#/책 예제16

C# Task 비동기 API 예제 using System; using System.IO; using System.Threading.Tasks; namespace ThreadNTask { class Program { static void Main(string[] args) { if(args.Length < 2) { Console.WriteLine("Usage: AsyncFileIO "); return; } DoCopy(args[0], args[1]); Console.ReadLine(); } static async Task CopyAsync(string fromPath, string toPath) { using(var fromStream = new FileStream(fromPath, FileMode.Open)) { long totalCop.. 2019. 6. 8.
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.
300x250