private void OnTasksCompleted()
{
if (_synchronizationContext == SynchronizationContext.Current)
{
var tasksCompleted = TasksCompleted;
if (tasksCompleted != null)
{
// Execute event on the current thread
tasksCompleted(this, null);
}
}
else
{
// Post the event on the creator thread
_synchronizationContext.Post(new SendOrPostCallback(delegate(object state)
{
var tasksCompleted = TasksCompleted;
if (tasksCompleted != null)
{
tasksCompleted(this, null);
}
}), null);
}
}