Created
April 23, 2014 14:27
-
-
Save qwerty2501/11217368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AsyncClass | |
{ | |
//この通知によってライブラリユーザはGUIを更新することが高いと予想される | |
public event Action SomeEventHandler; | |
public async Task DoAsync() | |
{ | |
//ここまでGUIスレッドで実行されているとする | |
//.ConfigureAwait(false)でUIスレッドに戻さない | |
await HeavyWorkAsync().ConfigureAwait(false); | |
//この非同期メソッドではConfigureAwait(false)しない | |
await SomeAsync(); | |
//イベント呼び出し時にはGUIスレッドに戻っているか? | |
SomeEventHandler(); | |
} | |
private Task<int> SomeAsync() | |
{ | |
return Task.FromResult(0); | |
} | |
private static Task HeavyWorkAsync() | |
{ | |
return Task.Delay(TimeSpan.FromSeconds(5)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment