비동기 호출의 병렬 처리 하기 입니다. 아래의 예제는 병렬 처리 하기 전입니다. using System; using System.IO; using System.Threading; using System.Threading.Tasks; namespace TaskSample { class Program { static void Main(string[] args) { int result3 = Method3(); int result5 = Method5(); Console.WriteLine(result3 + result5); } private static int Method3() { Thread.Sleep(3000); // 3초가 걸리는 작업을 대신해서 sleep 처리 return 3; } private stati..
ReadAllText 메서드를 비동기로 처리하기 입니다. 별도의 스레드를 이용하거나 델리게이트의 BeginInvoke로 처리하여 비동기를 적용하는 예제입니다.(복잡함) using System; using System.IO; namespace TaskSample { class Program { public delegate string ReadAllTextDelegate(string path); static void Main(string[] args) { string filePath = @"C:\windows\system32\drivers\etc\HOSTS"; ReadAllTextDelegate func = File.ReadAllText; func.BeginInvoke(filePath, actionCompl..
await 없이 Task타입을 단독으로 사용하는 예제 입니다. Task 타입은 반환값이 없는 경우 사용되며, Task 타입은 TResult 형식 매개 변수로 지정된 반환값이 있는 경우로 구분됩니다. using System; using System.Threading; using System.Threading.Tasks; namespace TaskSample { class Program { static void Main(string[] args) { ThreadPool.QueueUserWorkItem((obj) => { Console.WriteLine("process workItem"); }, null); Task task1 = new Task(() => { Console.WriteLine("Process ..

using System; using System.IO; using System.Threading.Tasks; using System.Windows.Forms; namespace FileCopy { /// /// 메인폼 클래스 입니다. /// public partial class MainForm : Form { // Constructor (Public) #region MainForm() - 생성자 입니다. /// /// 생성자 입니다. /// public MainForm() { InitializeComponent(); #region 이벤트를 설정합니다. this.sourceButton.Click += sourceButton_Click; this.targetButton.Click += targetButton..
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..
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..
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..
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]..
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..
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..
- Total
- 71,403
- Today
- 5
- Yesterday
- 151
- TextEdit
- node
- mariadb
- DevExpress
- SQLite
- DateEdit
- GridControl
- ContextMenuStrip
- CheckedListBoxControl
- TreeView
- EditMask
- TreeList
- Datasource
- gridview
- CheckEdit
- 전체 선택
- Chart
- Await
- winform
- LookUpEdit
- DataGridView
- ComboBox
- ComboBoxEdit
- c#
- PostgreSQL
- BAR
- database
- task
- RepositoryGridLookUpEdit
- 비동기