Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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