Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Last active January 2, 2016 18:19
Show Gist options
  • Select an option

  • Save JakeGinnivan/8342493 to your computer and use it in GitHub Desktop.

Select an option

Save JakeGinnivan/8342493 to your computer and use it in GitHub Desktop.
SyncCtx/IsThreadPool/ThreadId: System.Windows.Threading.DispatcherSynchronizationContext/False/8
SyncCtx/IsThreadPool/ThreadId: System.Windows.Threading.DispatcherSynchronizationContext/True/10
SyncCtx/IsThreadPool/ThreadId: System.Windows.Threading.DispatcherSynchronizationContext/False/8
SyncCtx/IsThreadPool/ThreadId: /True/11
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace WpfApplication3
{
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Debug.WriteLine("SyncCtx/IsThreadPool/ThreadId: {0}/{1}/{2}", SynchronizationContext.Current, Thread.CurrentThread.IsThreadPoolThread,
Thread.CurrentThread.ManagedThreadId);
await TaskEx.Run(() => Thread.Sleep(1000)).ConfigureAwait(false);
Debug.WriteLine("SyncCtx/IsThreadPool/ThreadId: {0}/{1}/{2}", SynchronizationContext.Current, Thread.CurrentThread.IsThreadPoolThread,
Thread.CurrentThread.ManagedThreadId);
}
}
}
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Click="ButtonBase_OnClick" Content="Do Stuff" />
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment