動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
関連: Visual Studio | WPF > 非同期処理 > Link: ざっくりマルチスレッド(非同期処理)
Asynchronous Programming with Async and Await (C# and Visual Basic)
を読んで興味を持った部分は以下の通り。
- .NET Framework 4.5
- Application areaのテーブル
- async and await keywords
- an Async or async modifier
- The method signature includes an Async or async modifier.
- 補足: method signatureには修飾語も含まれる?
- "Async" suffix
- Task if ... has type TResult
- Void ... an async event handler
- how the control flow moves
- returns ...
Task<int>
to the caller - If GetStringAsync ... is complete before AccessTheWebAsync awaits it, ...
- 補足: いくつかのRTOSなどでもこのような処理には違いがあることを経験している
- awaitをする前に処理が終了した場合にawaitが失敗する場合
- awaitをする前に処理が終了した場合にawaitが成功する場合
- など
- API Aync Methods
- .NET Framework 4.5 contains ...
- 補足: XXXAsync()というような関数がある
- Async ... non-blocking operations
- runs on the current synchronization context
- 補足: 別スレッドにはしない、とのこと
- race conditions
- 補足: mutexやsemaphoreやdeadlock関連で出てくる用語
- ... returns a Task or a Task
- 誤植:
Task<T>
もしくはTask<TResult>
- 誤植:
Task<TResult>
- An async method can't declare ByRef parameters in Visual Basic or ref or out parameters in C#, but the method can call methods that have such parameters.
呼び出し方法
XXXAsync()を呼ぶ方法について、二通りの記載があった。
Return Types and Parameters
// Calls to TaskOfTResult_MethodAsync
Task<int> returnedTaskTResult = TaskOfTResult_MethodAsync();
int intResult = await returnedTaskTResult;
// or, in a single statement
int intResult = await TaskOfTResult_MethodAsync();
前者を使うと良い状況については今後知ることになるだろう。