Skip to content

Instantly share code, notes, and snippets.

@yasu-s
Created February 18, 2016 12:46
Show Gist options
  • Save yasu-s/ee2e0d31202e8daffc58 to your computer and use it in GitHub Desktop.
Save yasu-s/ee2e0d31202e8daffc58 to your computer and use it in GitHub Desktop.
アクティブなタスクを完了まで待つ処理
/// <summary>
/// ActiveTask完了まで待つ処理
/// async void されてしまったTaskの完了を待つ
/// </summary>
public static void WaitActiveTasks()
{
var m = typeof(Task).GetMethod("GetActiveTasks", BindingFlags.NonPublic | BindingFlags.Static);
while (true)
{
var tasks = m.Invoke(typeof(Task), null) as Task[];
if (tasks.Any())
System.Threading.Thread.Sleep(100);
else
break;
}
}
@yasu-s
Copy link
Author

yasu-s commented Feb 18, 2016

Fire & Forget されたメソッドの待機用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment