Skip to content

Instantly share code, notes, and snippets.

@renestein
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renestein/864d957ac59b9f3d59cc to your computer and use it in GitHub Desktop.
Save renestein/864d957ac59b9f3d59cc to your computer and use it in GitHub Desktop.
public virtual Task Post(Action action)
{
checkIfDisposed();
if (action == null)
{
throw new ArgumentNullException("action");
}
return postInner(() => Dispatch(action));
}
public virtual Task Post(Func<Task> function)
{
checkIfDisposed();
if (function == null)
{
throw new ArgumentNullException("function");
}
return postInner(() => Dispatch(function));
}
private Task postInner(Func<Task> dispatcher)
{
bool oldIsInServiceThread = m_isServiceThreadFlags.Value.IsServiceThread;
try
{
clearCurrentThreadAsServiceFlag();
return dispatcher();
}
finally
{
m_isServiceThreadFlags.Value.IsServiceThread = oldIsInServiceThread;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment