Last active
August 21, 2023 07:08
-
-
Save LuviKunG/7c9f253f22f5590cd898a8178b3c66fe to your computer and use it in GitHub Desktop.
C# extension that helps async to callback main thread sync.
This file contains hidden or 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.Tasks; | |
namespace LuviKunG.Extensions | |
{ | |
public static class TaskSchedulerExtensions | |
{ | |
public static Task ContinueWithCurrentSynchronizationContext(this Task task, Action<Task> action) | |
{ | |
return task.ContinueWith(action, TaskScheduler.FromCurrentSynchronizationContext()); | |
} | |
public static Task ContinueWithCurrentSynchronizationContext<T>(this Task<T> task, Action<Task<T>> action) | |
{ | |
return task.ContinueWith(action, TaskScheduler.FromCurrentSynchronizationContext()); | |
} | |
public static Task<T> ContinueWithCurrentSynchronizationContext<T>(this Task task, Func<Task, T> action) | |
{ | |
return task.ContinueWith(action, TaskScheduler.FromCurrentSynchronizationContext()); | |
} | |
public static Task<T> ContinueWithCurrentSynchronizationContext<T>(this Task<T> task, Func<Task, T> action) | |
{ | |
return task.ContinueWith(action, TaskScheduler.FromCurrentSynchronizationContext()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment