csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
using System;
|
|
using System.Threading;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Threading;
|
|
using CoreFoundation;
|
|
using Foundation;
|
|
|
|
namespace Avalonia.iOS
|
|
{
|
|
class PlatformThreadingInterface : IPlatformThreadingInterface
|
|
{
|
|
private bool _signaled;
|
|
public static PlatformThreadingInterface Instance { get; } = new PlatformThreadingInterface();
|
|
public bool CurrentThreadIsLoopThread => NSThread.Current.IsMainThread;
|
|
|
|
public event Action<DispatcherPriority?> Signaled;
|
|
public void RunLoop(CancellationToken cancellationToken)
|
|
{
|
|
//Mobile platforms are using external main loop
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick)
|
|
=> NSTimer.CreateRepeatingScheduledTimer(interval, _ => tick());
|
|
|
|
public void Signal(DispatcherPriority prio)
|
|
{
|
|
lock (this)
|
|
{
|
|
if(_signaled)
|
|
return;
|
|
_signaled = true;
|
|
}
|
|
|
|
DispatchQueue.MainQueue.DispatchAsync(() =>
|
|
{
|
|
lock (this)
|
|
_signaled = false;
|
|
Signaled?.Invoke(null);
|
|
});
|
|
}
|
|
}
|
|
}
|