-
-
Save DavidKarlas/c914ef6d6dcb0e3bb9db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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