Skip to content

Instantly share code, notes, and snippets.

@nigel-sampson
Created November 6, 2012 20:43
Show Gist options
  • Save nigel-sampson/4027391 to your computer and use it in GitHub Desktop.
Save nigel-sampson/4027391 to your computer and use it in GitHub Desktop.
TaskScheduler
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
SetUIThreadMarshaller(action =>
{
if (Window.Current != null)
action();
else
Task.Factory.StartNew(action, new CancellationToken(), TaskCreationOptions.PreferFairness, scheduler).Wait();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment