Pointless Waymarks Tools

Artifact [e579261e45]
Login

Artifact [e579261e45]

Artifact e579261e45337b953f7b589cd9df6b4a4f24c7b0a43d38cac4d21138ba16d786:


using System.Runtime.CompilerServices;

namespace PointlessWaymarks.WpfCommon;

public struct ThreadPoolThreadSwitcher : INotifyCompletion
{
    public bool IsCompleted => SynchronizationContext.Current == null;

    public ThreadPoolThreadSwitcher GetAwaiter()
    {
        //Debug.Print($"ThreadPoolThreadSwitcher GetAwaiter from {Thread.CurrentThread.ManagedThreadId}");
        return this;
    }

    public void GetResult()
    {
    }

    public void OnCompleted(Action continuation)
    {
        //Debug.Print($"ThreadPoolThreadSwitcher OnCompleted from {Thread.CurrentThread.ManagedThreadId}");
        ThreadPool.QueueUserWorkItem(_ => continuation());
    }
}