์ ๋ํฐ/C# ๊ฐ๋ 6
-
-
๋น๋๊ธฐ ์ทจ์: CancellationTokenSource ๋๋ณด๊ธฐ CancellationTokenSource tokenSource; public Form1() { InitializeComponent(); } //๋น๋๊ธฐ ๋ฉ์๋ private async Task DoWorkAsync(CancellationToken token) { while (!token.IsCancellationRequested) //๋ฌดํ๋ฃจํ { await Task.Delay(100); //๋๋ ์ด int.TryParse(lblIndex.Text, out var value); lblIndex.Text = (++value).ToString(); } } private async void btnStart_Click(object sender, Eve..
-
๋๊ธฐ(Synchronous) ๋ฉ์๋๊ฐ ์๋ฃ๋ ๋๊น์ง ์ฝ๋ ์คํ์ด ์ฐจ๋จ๋๋ ๊ฒ ์์ ์ ์์๋๋ก ์คํ๋๋ฏ๋ก ํ๋์ ์์ ์ด ๋๋ ๋๊น์ง ๋ค๋ฅธ ์์ ์ ์ํํ์ง ์์ ์ฝ๋ //๋๊ธฐ ๋ฉ์๋ private void RunAnything(Label lbl) //์๋ฌด๊ฑฐ๋ ์คํํ๋ ํจ์ { for (int i = 0; i < 30; i++) { Thread.Sleep(100); //์ค๋ ๋๋ฅผ ์ด์ฉํด ์ฝ๊ฐ์ ๋๋ ์ด๋ฅผ ์ค. ๋ฃจํ 1ํ๋น 0.1์ด์ ๋๋ ์ด lbl.Text = i.ToString(); //๋ฃจํ ์ธ๋ฑ์ค๋งํผ ํ๋ฉด์์ ๋ณด์ฌ์ค lbl.Refresh(); //ํ๋ฉด์์ ๋ณด์ฌ์ค์ผํจ } } //๋๊ธฐ private void btnWalking_Click(object sender, EventArgs e) { RunAnything(l..
-
๊ณผ๊ฑฐ c# ๋ฌธ๋ฒ์ ์์ฌํ๋ ๊ฒ์ผ๋ก, ํ์ฌ Action์ด๋ ๋ธ๋ฆฌ๊ฒ์ดํธ์ ๋ด๊ฒจ์ง ํจ์๊ฐ ์กด์ฌํ๋ค๋ฉด ์คํํ๊ณ ๊ทธ๋ ์ง ์๋ค๋ฉด ์คํํ์ง ๋ง๋ผ๋ ์์ธ ์ฒ๋ฆฌ๊ฐ ์ถ๊ฐ๋ Invoke ํํ a?.b() ๋ if (a != null) { a.b(); } ํน์ a == null ? null : a.b() ์ ๊ฐ์ action์ด๋ delegate ๊ฐ์ ๊ฒฝ์ฐ, action(); ๋ action.Invoke(); ๋ ๋์ผํจ
-
-
์ฝ๋ฃจํด ์ ์ Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. ์คํ์ ์ง์ฐ๊ณผ ์ฌ๊ฐ๋ฅผ ํ์ฉํจ์ผ๋ก์, ๋น ์ ์ ์ ๋ฉํฐํ์คํน์ ์ํ ์๋ธ๋ฃจํด์ ์ผ๋ฐํํ ์ปดํจํฐ ํ๋ก๊ทธ๋จ ๊ตฌ์ฑ์์ ์ค๋ช ๋ณํ์ฑ, ๋์์ฑ(Concurrency) ๋ณ๋ ฌ์ฑ(Parallelism) ๋น ์ ์ ์ ๋ฉํฐํ์คํน (Non-preemptive multitasking) CPU๋ฅผ ์ฐจ์งํ๊ณ ์๋ ์ฐ๋ ๋๊ฐ CPU ์ฐ์ฐ์ด ํ์์์์ ๋ํ๋์ ๋, ์ด์์ฒด์ ๊ฐ ํ์ํ ์ ์๋ ๊ฒฝ์ฐ โญ๏ธ โ ์ ์ ํ ๋ฉํฐํ์คํน (Preemptive multit..