ImmediateDispatcher.cs 979 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Threading.Tasks;
  3. using Avalonia.Threading;
  4. namespace Avalonia.UnitTests
  5. {
  6. /// <summary>
  7. /// Immediately invokes dispatched jobs on the current thread.
  8. /// </summary>
  9. public class ImmediateDispatcher : IDispatcher
  10. {
  11. public bool CheckAccess()
  12. {
  13. return true;
  14. }
  15. public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
  16. {
  17. action();
  18. }
  19. public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
  20. {
  21. action();
  22. return Task.FromResult<object>(null);
  23. }
  24. public Task<TResult> InvokeAsync<TResult>(Func<TResult> function, DispatcherPriority priority = DispatcherPriority.Normal)
  25. {
  26. var result = function();
  27. return Task.FromResult(result);
  28. }
  29. public void VerifyAccess()
  30. {
  31. }
  32. }
  33. }