Skip to content

Instantly share code, notes, and snippets.

@DavidKarlas
Created November 4, 2015 11:17
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 DavidKarlas/c914ef6d6dcb0e3bb9db to your computer and use it in GitHub Desktop.
Save DavidKarlas/c914ef6d6dcb0e3bb9db to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
public class HelloWorld : Form
{
static public void Main ()
{
Application.Run (new HelloWorld ());
}
static Thread mt;
public HelloWorld ()
{
mt = Thread.CurrentThread;
TaskScheduler ts = TaskScheduler.FromCurrentSynchronizationContext (); // Get the UI task scheduler
var task = Task.Factory.StartNew (() => {
});
var cont = task.ContinueWith (MyContinueWith, CancellationToken.None, TaskContinuationOptions.None, ts);
}
void MyContinueWith (Task t)
{
Console.WriteLine ("Got here");
if (mt != Thread.CurrentThread)
Console.WriteLine ("threads are different");
if (SynchronizationContext.Current == null) // The current SynchronizationContext shouldn't be null here, but it is.
Console.WriteLine ("SynchronizationContext.Current is null");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment